当绘图针对图形边缘运行时添加边距

end*_*ith 10 python plot matplotlib

通常当我在matplotlib中绘图时,我得到这样的图形:

频率响应沿着上边缘运行

您无法看到该功能,因为它会在绘图边缘上运行.

有没有办法在这些情况下自动添加一些边距,所以它们看起来像这样:

具有微小噪声的频率响应

bmu*_*bmu 17

您可以使用它ax.margins()来设置边距.例:

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

In [2]: ax.plot(np.arange(10), '-o')
Out[2]: [<matplotlib.lines.Line2D at 0x302fb50>]
Run Code Online (Sandbox Code Playgroud)

没有保证金

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

In [2]: ax.margins(0.05)

In [3]: ax.plot(np.arange(10), '-o')
Out[3]: [<matplotlib.lines.Line2D at 0x302fb50>]
Run Code Online (Sandbox Code Playgroud)

有保证金

您也可以只设置x或y边距.但是它似乎不是一个matplotlibrc选项,因此您可以简单地将其设置为默认行为(因此它不是完全自动的).我打开了一个github问题来请求这个.