matplotlib轴(“紧")不起作用? [英] matplotlib axis('tight') doesn't work?

查看:37
本文介绍了matplotlib轴(“紧")不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据

我可能做错了什么?

解决方案

通过设置 autoscale ,您应该会看到 tight = True tight之间的理想差异= False .

  f,(ax,ax2)= plt.subplots(ncols = 2)ax.plot([0,1],[1,0],label ="tight = True")ax.autoscale(enable = True,axis ='both',tight = True)ax2.plot([0,1],[1,0],label ="tight = False")ax2.autoscale(enable = True,axis ='both',ight = False)ax.legend()ax2.legend() 

您可能会注意到 ax.axis("tight")无关;它仅在文档中指出

设置紧密"限制,以便显示所有数据

确实是这种情况,所有数据都会显示出来(它并没有说明将视图限制设置为准确的数据).

According to the documentation, ax.autoscale(tight=True) should

If True, set view limits to data limits;

With ax.axis('tight') being similar:

‘tight’      Limits set such that all data is shown

(sic)

And we even see that it works in the screenshots of this question.

But no matter what I try, it doesn't seem to work with the following simple example. Here's what I typed into jupyter-qtconsole:

In [27]: f, ax = plt.subplots(1)

In [28]: ax.plot([0, 1], [1, 0])
Out[28]: [<matplotlib.lines.Line2D at 0x825abf0>]

In [29]: ax.axis('tight')
Out[29]: (-0.050000000000000003, 1.05, -0.050000000000000003, 1.05)

In [30]: ax.autoscale(tight=True)

In [31]: plt.axis('tight')
Out[31]: (-0.050000000000000003, 1.05, -0.050000000000000003, 1.05)

In [32]: plt.autoscale(tight=True)

In [33]: ax.plot([0, 1], [1, 0])
Out[33]: [<matplotlib.lines.Line2D at 0x825a4d0>]

In [34]: ax.autoscale(enable=True, axis='x', tight=True)

Throughout these commands, the limits of the plot don't change:

What might I be doing wrong?

解决方案

By setting the autoscale you should see the desired difference between tight=True and tight=False.

f, (ax, ax2) = plt.subplots(ncols=2)

ax.plot([0, 1], [1, 0], label="tight=True")
ax.autoscale(enable=True, axis='both', tight=True)

ax2.plot([0, 1], [1, 0], label="tight=False")
ax2.autoscale(enable=True, axis='both', tight=False)

ax.legend()
ax2.legend()

You may note that ax.axis("tight") is not related; it only states in the documentation that

‘tight’ Limits set such that all data is shown

which is indeed the case, all data is shown (it doesn't say anything about setting the view limits to exactly the data).

这篇关于matplotlib轴(“紧")不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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