gpt4 book ai didi

python - 为什么 set_xlim() 没有在我的图中设置 x 限制?

转载 作者:IT老高 更新时间:2023-10-28 20:41:15 27 4
gpt4 key购买 nike

我正在用 matplotlib 绘制一些数据。我希望情节专注于特定范围的 x 值,所以我使用 set_xlim()。

大致上,我的代码如下所示:

fig=plt.figure()
ax=fig.add_subplot(111)
for ydata in ydatalist:
ax.plot(x_data,y_data[0],label=ydata[1])
ax.set_xlim(left=0.0,right=1000)
plt.savefig(filename)

当我查看绘图时,x 范围最终是从 0 到 12000。无论 set_xlim() 发生在 plot() 之前还是之后,都会发生这种情况。为什么 set_xlim() 在这种情况下不起作用?

最佳答案

出于好奇,换成旧的 xminxmax 怎么样?

fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x_data,y_data)
ax.set_xlim(xmin=0.0, xmax=1000)
plt.savefig(filename)

关于python - 为什么 set_xlim() 没有在我的图中设置 x 限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17734587/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com