如何设置轴补丁的大小,以便不剪裁绘图标签(matplotlib)

How do I set the size of the axes patch so that the plot labels aren't clipped (matplotlib)

我有一个图表,其中我使用

将轴标签设置为科学记数法

formatter = mpl.ticker.FormatStrFormatter('%4.2e') axis2.yaxis.set_major_formatter(formatter)

然而,axes.patch(或任何表达图 'canvas' 范围的正确方法)不会调整,因此刻度标签和轴标签被剪裁:

如何调整绘图轴部分的范围。更改页面大小 (figsize = ...) 不会这样做,因为这只会缩放整个绘图区域,导致相同的裁剪问题。

只需调用 fig.tight_layout()(假设您定义了一个 Figure 对象)。

您可以使用方法 tight_layout,它将容纳可用图中的绘图 space。

例子

from pylab import *
f = figure()
f.add_subplot(111)
f.tight_layout()
show()

希望对您有所帮助。

干杯