试使用 plt.tight_layout
作为一个简单的例子:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=4, ncols=4)
fig.tight_layout() # Or equivalently, "plt.tight_layout()"
plt.show()
没有紧凑的布局
您可以plt.subplots_adjust
用来更改子图之间的间距(源)
通话签名:
subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
参数含义(和建议的默认值)为:
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 0.9 # the top of the subplots of the figure
wspace = 0.2 # the amount of width reserved for blank space between subplots
hspace = 0.2 # the amount of height reserved for white space between subplots