当matplotlib
制作图形时,我发现它“填充”了轴周围的空间,不符合我的口味(并且以不对称的方式)。例如与
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x, y = 12*np.random.rand(2, 1000)
ax.set(xlim=[2,10])
ax.plot(x, y, 'go')
我得到的东西看起来像
(此处以 Adobe Illustrator 为例)。
我希望图形的边界在所有侧面都更接近轴,特别是在左侧和右侧。
如何在 matplotlib
中以编程方式相对于每个轴调整这些边界?
最佳答案
尝试:
plt.tight_layout()
默认参数设置为:
plt.tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None)
关于python - 如何收紧 'matplotlib' 数字的边界以使其更接近我的轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20732347/