开发者

change matplotlib axis settings

How do I get control over the axis settings of a pyplot plot. I hav开发者_JS百科e simply done

    pylab.plot(*self.plot_generator(low, high))

    pylab.show()

and I get this which is what I want

change matplotlib axis settings

but I want the x axis to be at 0 instead of at the bottom. How would I do that?


# create some data
x = np.linspace(-np.pi,np.pi,100)
y = np.cos(2.5*x)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y, mfc='orange', mec='orange', marker='.')

# using 'spines', new in Matplotlib 1.0
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

ax.axhline(linewidth=2, color='blue')
ax.axvline(linewidth=2, color='blue')
show()

change matplotlib axis settings


To set start of x-axis to 0:

pylab.xlim(xmin=0)

To set start of y-axis to 0:

pylab.ylim(ymin=0)

Put one of these lines (or both if you'd like) after the pylab.plot call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜