Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib轴(';紧';)不';不行?_Python_Matplotlib_Layout_Plot_Axes - Fatal编程技术网

Python matplotlib轴(';紧';)不';不行?

Python matplotlib轴(';紧';)不';不行?,python,matplotlib,layout,plot,axes,Python,Matplotlib,Layout,Plot,Axes,根据ax。自动缩放(tight=True)应该 如果为True,则将视图限制设置为数据限制 与之相似: 设置“严格”限制,以便显示所有数据 (原文如此) 我们甚至可以在的截图中看到它的作用 但不管我怎么做,下面这个简单的例子似乎都不起作用。以下是我在jupyter qtconsole中输入的内容: In [27]: f, ax = plt.subplots(1) In [28]: ax.plot([0, 1], [1, 0]) Out[28]: [<matplotlib.lines.Li

根据ax。自动缩放(tight=True)应该

如果为True,则将视图限制设置为数据限制

与之相似:

设置“严格”限制,以便显示所有数据

(原文如此)

我们甚至可以在的截图中看到它的作用

但不管我怎么做,下面这个简单的例子似乎都不起作用。以下是我在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)
[27]中的
:f,ax=plt.子批次(1)
[28]中的ax.plot([0,1],[1,0])
Out[28]:[]
在[29]中:最大轴(“紧”)
出[29]:(-0.05000000000000003,1.05,-0.05000000000000003,1.05)
[30]中:最大自动缩放(紧密=真)
[31]中:plt.轴(“紧”)
输出[31]:(-0.05000000000000003,1.05,-0.05000000000000003,1.05)
In[32]:plt.自动缩放(紧密=真)
[33]中的ax.plot([0,1],[1,0])
Out[33]:[]
在[34]中:ax.自动缩放(启用=真,轴=x',紧密=真)
在这些命令中,绘图的限制不会改变:


我可能做错了什么?

你不一定做错了什么。您正在使用matplotlib版本2(或更高版本)。在此版本中,默认打印布局已更改,因此轴的两端都添加了5%的填充。以下是描述绘图布局的链接:

在链接中,要将其更改回“经典”样式,请使用:

mpl.rcParams['axes.autolimit_mode'] = 'round_numbers'
mpl.rcParams['axes.xmargin'] = 0
mpl.rcParams['axes.ymargin'] = 0

通过设置
自动缩放
,您应该可以看到
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', tight=False)

ax.legend()
ax2.legend()

您可能会注意到,
ax.axis(“紧”)
不相关;它仅在文档中声明:

设置“严格”限制,以便显示所有数据


确实如此,所有数据都会显示出来(它并没有说要将视图限制设置为与数据完全一致)。

这就行了。我将
mpl.rcParams['axes.autolimit_mode']
保留为默认值
'data'
,使帧符合数据限制,而不是下一个勾号(即
'round_number'
行为)。另外,我要说的是,它有点违背常识,特别要求
axis('tight')
不会折叠这些边距,这很有趣,因为当我复制粘贴这段代码时,我得到两个图,它们都看起来像你的右手边图。然而,从线条的颜色,我推断您也在使用Matplotlib 2+(除非您更改了Matplotlib 1.3的配色方案?)您的
Matplotlib.rcParams['axes.xmargin']
?我使用的是Matplotlib 2.0.2,边距是默认的
print Matplotlib.rcParams['axes.xmargin']#结果为0.05
。这就解决了问题!自3月份以来,我就没有更新过Python库<代码>matplotlib.\uuuuu版本\uuuuu是
'2.0.0b3'
。从那时起,它一定已经修好了。