python - how can I plot on the axes -
i want recreate image following:
specially little x on xaxes have
list = [[100,-3],[200,none],[120,-2] ... ]
and do
for x in list: if x[1]!=none: plot(x[0],x[1],'ok') else: ### plot on axes ###
but while plotting not know axes are. know values none, example ( 250,none), want plot on xaxes @ x = 250, have not idea min(ylim()) be.
i know can plot(250,-5,'x',zorder=999999)
when know min axes is.. (i can not min, max , know min axes. real data list inside list inside dictionary etc.. )
so trick use custom transformation. regular data transformation x axis , axes transformation y axis. matplotlib calls blended transformation, need create yourself. you'll find more information in awesome guide.
and @thepredator pointed out, have set clip_on=false
, otherwise markers clipped.
import numpy np import matplotlib.pyplot plt import matplotlib.transforms transforms fig, ax = plt.subplots() # x coords of transformation data, , # y coord axes trans = transforms.blended_transform_factory( ax.transdata, ax.transaxes) # data points on axes x = np.random.rand(5)*100. + 200. y = [0]*5 ax.plot(x, y, 'kx', transform=trans, markersize=10, markeredgewidth=2, clip_on=false) # regular data x = np.random.rand(5)*100. + 200. y = np.random.rand(5)*100. + 200. ax.plot(x, y, 'ro') plt.show()
result:
Comments
Post a Comment