我该如何控制pyplot绘图的轴设置?我只是简单地执行了以下操作:
pylab.plot(*self.plot_generator(low, high))
pylab.show()
我得到了我想要的结果,如下所示:
但是我希望x轴从0开始而不是从底部开始。我该怎么做?
pylab.plot(*self.plot_generator(low, high))
pylab.show()
我得到了我想要的结果,如下所示:
但是我希望x轴从0开始而不是从底部开始。我该怎么做?
# 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()
将x轴的起始点设置为0:
pylab.xlim(xmin=0)
将 y 轴起始值设为 0:pylab.ylim(ymin=0)
在pylab.plot
调用之后,加入以下任意一行代码(或两行都加入,如果需要的话)。
ax.spines
吗?据我所知,所有的方法set_position
或set_color
都是matplotlib.spines.Spine
类对象的成员。这很令人困惑。 - haccksax.spines
是一个包含四个Spine
对象的OrderedDict
:'left'
、'right'
、'top'
和'bottom'
。 - teekarnaaxhline
和axvline
命令。如果想要改变坐标轴的线宽或颜色,最好是改变坐标轴属性。 - teekarna