更改 matplotlib 轴设置 [英] change matplotlib axis settings

查看:29
本文介绍了更改 matplotlib 轴设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何控制 pyplot 图的轴设置.我简单做了

How do I get control over the axis settings of a pyplot plot. I have simply done

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

    pylab.show()

我得到了这就是我想要的

and I get this which is what I want

但我希望 x 轴位于 0 而不是底部.我该怎么做?

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()

这篇关于更改 matplotlib 轴设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆