[英]In matplotlib, what is the difference betweent set_xlim and set_xbound?
From the help:来自帮助:
set_xlim: Set the data limits for the xaxis. set_xlim:设置 x 轴的数据限制。
set_xbound: Set the lower and upper numerical bounds of the x-axis. set_xbound:设置x轴的数值上下界。
That is not very clear, so let's say that I plot something:这不是很清楚,所以假设我 plot 一些东西:
import matplotlib.pylab as plt
fig, ax = plt.subplots(1, 1)
ax.plot(xrange(10), xrange(10))
Now, either I do:现在,要么我这样做:
ax.set_xlim(2, 7)
or:或者:
ax.set_xbound(2, 7)
I do not see the difference.我看不出有什么区别。 I can dragg the plot, all the line is ploted between 0 and 9.我可以拖动 plot,所有的线都绘制在 0 和 9 之间。
The bound can changes automatically, if you later plot something that is not within the bound. 如果您以后绘制不在边界内的对象,则边界会自动更改。 In contrast, limits are fixed and do not change automatically. 相反,限制是固定的,不会自动更改。
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()
After examining the source, we can see that set_xbound(lower, upper)
makes a call to set_xlim
with arguments passed like so, self.set_xlim(sorted((lower, upper), reverse=bool(self.xaxis_inverted())), auto=None)
检查源代码后,我们可以看到set_xbound(lower, upper)
调用了set_xlim
并传递了 arguments, self.set_xlim(sorted((lower, upper), reverse=bool(self.xaxis_inverted())), auto=None)
So set_xbound
is very similar to calling set_xlim
with auto=None
which will not change auto-scaling settings, the default when you call set_xlim
will set auto=False
which disables auto-scaling.因此set_xbound
与使用auto=None
调用set_xlim
非常相似,后者不会更改自动缩放设置,当您调用set_xlim
时默认设置auto=False
以禁用自动缩放。 This is why bounds may be altered later on by auto-scaling, as the default is to auto-scale, unless explicitly turned off (or implicitly by a method like set_xlim
).这就是为什么稍后可以通过自动缩放更改边界的原因,因为默认设置是自动缩放,除非明确关闭(或通过set_xlim
类的方法隐式关闭)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.