按照documentation,ax.autoscale(tight=True)
应该matplotlib axis('tight')不起作用?
如果为True,设置视图限制数据限制;
随着ax.axis('tight')
是相似的:
'紧' 限制设置,使得所有的数据都显示
(原文如此)
我们甚至看到它可以在this question的屏幕截图中使用。
但无论我尝试什么,它似乎都不适用于下面的简单示例。这是我键入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)
纵观这些命令,该地块的限制不会改变:
什么可能我是做错了什么?
工作。我将'mpl.rcParams ['axes.autolimit_mode']'留在了'data'的默认值,这符合数据极限,而不是下一个勾号(即'round_numbers'行为)。另外,我想说的是,它与一般常识略有不同,特别要求'axis('tight')'不会折叠这些边距,这似乎可以在每个plot的基础上进行(https: //stackoverflow.com/a/41748745/1143274)。 –