【发布时间】:2010-11-27 02:55:55
【问题描述】:
如何控制 pyplot 绘图的轴设置。我已经完成了
pylab.plot(*self.plot_generator(low, high))
pylab.show()
我得到了这就是我想要的
但我希望 x 轴位于 0 而不是底部。我该怎么做?
【问题讨论】:
标签: python matplotlib scipy
如何控制 pyplot 绘图的轴设置。我已经完成了
pylab.plot(*self.plot_generator(low, high))
pylab.show()
我得到了这就是我想要的
但我希望 x 轴位于 0 而不是底部。我该怎么做?
【问题讨论】:
标签: python matplotlib scipy
# 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()
【讨论】:
ax.spines。 AFAIK,所有方法set_position 或set_color 都是matplotlib.spines.Spine 类对象的成员。这令人困惑。
ax.spines 是一个 OrderedDict,它包含四个 Spine 对象:'left'、'right'、'top' 和 'bottom'。
axhline、axvline 命令。如果想更改坐标轴的线宽或颜色,最好更改坐标轴属性。
将 x 轴的起点设置为 0:
pylab.xlim(xmin=0)
将 y 轴的起点设置为 0:
pylab.ylim(ymin=0)
在pylab.plot 调用之后添加这些行之一(或者如果您愿意,可以同时添加)。
【讨论】: