在Matplotlib中为绘图添加空白区域
我有一个固定大小的图形,想要调整里面的绘图大小,也就是在周围加一些空白区域。网上大多数问题都是在讨论怎么去掉空白或者处理子图,而我这里没有这些问题。
我的绘图代码是
fig = plt.figure(figsize=(14,10))
plt.plot(n, y)
plt.savefig('figure.png', bbox_inches='tight', dpi=200)
其实也没什么特别的。我已经试过 margins
和 tight_layout(pad = X)
,但是都没有效果。
1 个回答
1
你可以通过使用 subplots_adjust
来调整子图的参数。
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(14, 10))
plt.plot(n, y)
#Adjust the subplot parameters to add white space
plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
plt.savefig('figure.png', dpi=200)
通过调整左、右、上和下的数值,你可以控制图表周围留出的空白区域的大小。