在matplotlib中,set xlim和set xbound之间有什么区别?

2024-04-25 12:19:24 发布

您现在位置:Python中文网/ 问答频道 /正文

从帮助:

设置xaxis的数据限制。

设置xbound:设置x轴的数值下限和上限。

这还不太清楚,所以让我们说,我策划了一些事情:

import matplotlib.pylab as plt
fig, ax = plt.subplots(1, 1)
ax.plot(xrange(10), xrange(10))

现在,要么我做:

ax.set_xlim(2, 7)

或:

ax.set_xbound(2, 7)

我看不出有什么不同。我可以画这个图,所有的线都画在0到9之间。


Tags: 数据importmatplotlibasfigpltax事情
1条回答
网友
1楼 · 发布于 2024-04-25 12:19:24

如果以后打印的内容不在绑定范围内,则绑定可以自动更改。相反,限制是固定的,不会自动改变。

import pylab as p

t = p.arange(0.0, 2.0, 0.01)
s = p.sin(2*p.pi*t)

ax=p.subplot(111)
ax.plot(t, s, color='r',linewidth=1.0)
ax.set_ylim(-1,1)
ax.plot(t, s+1, color='g',linewidth=1.0, label="Graph2")
p.show()


ax=p.subplot(111)
ax.plot(t, s, color='r',linewidth=1.0)
ax.set_ybound(-1,1)
ax.plot(t, s+1, color='g',linewidth=1.0, label="Graph2")
p.show()

enter image description hereenter image description here

相关问题 更多 >