为什么 set_xlim() 没有在我的图中设置 x 限制? [英] Why is set_xlim() not setting the x-limits in my figure?

查看:54
本文介绍了为什么 set_xlim() 没有在我的图中设置 x 限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib绘制一些数据.我希望绘图专注于特定范围的 x 值,因此我使用 set_xlim().

I'm plotting some data with matplotlib. I want the plot to focus on a specific range of x-values, so I'm using set_xlim().

大致上,我的代码如下:

Roughly, my code looks like this:

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()在这种情况下不起作用?

When I look at the plot, the x range ends up being from 0 to 12000. This occurs whether set_xlim() occurs before or after plot(). Why is set_xlim() not working in this situation?

推荐答案

出于好奇,在旧的 xminxmax 中切换怎么样?

Out of curiosity, what about switching in the old xmin and xmax?

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)

这篇关于为什么 set_xlim() 没有在我的图中设置 x 限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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