1. 程式人生 > 其它 >如何縮小Matplotlib圖中的邊距

如何縮小Matplotlib圖中的邊距

技術標籤:筆記python

1.第一種方法

import matplotlib.pyplot as plt
import numpy as np
pic = np.arange(2000).reshape((100,20))
plt.imshow(pic)
plt.savefig('test.png', bbox_inches='tight')

2.第二種方法

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 20); y = np.sin(xs)
fig = plt.figure()
axes = fig.add_subplot(1,1,1)
axes.plot(x, y)
fig.tight_layout()
fig.savefig('test.png')