在 Matplotlib 中的绘图周围添加空白

问题描述 投票:0回答:1

我有一个固定大小的图形,想要更改其中绘图的大小,即在其周围添加空白。网上大多数问题都涉及删除空白或子图,而我没有。

我的绘图代码是

fig = plt.figure(figsize=(14,10))
plt.plot(n, y)
plt.savefig('figure.png', bbox_inches='tight', dpi=200)

所以真的没什么特别的。我已经尝试过

margins
tight_layout(pad = X)
但没有任何效果。

python matplotlib plot
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)

通过调整左、右、上、下的值,您可以控制绘图周围添加的空白量。

© www.soinside.com 2019 - 2024. All rights reserved.