在matplotlib中,set_xlim和set_xbound有什么区别? [英] In matplotlib, what is the difference betweent set_xlim and set_xbound?

查看:55
本文介绍了在matplotlib中,set_xlim和set_xbound有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从帮助中:

set_xlim:设置 xaxis 的数据限制.

set_xlim: Set the data limits for the xaxis.

set_xbound::设置x轴的上下边界.

set_xbound: Set the lower and upper numerical bounds of the x-axis.

这不是很清楚,所以让我说点什么:

That is not very clear, so let’s say that I plot something:

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 之间.

I do not see the difference. I can dragg the plot, all the line is ploted between 0 and 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()

这篇关于在matplotlib中,set_xlim和set_xbound有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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