プロットを matplotlib に表示しているときに、さまざまな寸法を使用して png として保存しようとしています。メインの図 (print_fig = fig) のコピーを作成してから、print_fig のサイズ (print_fig.set_size_inches(7,3)) を変更しています。ただし、これにより、print_fig だけでなく、元の図が変更されます。Figure オブジェクトを「複製」する方法はありますか?
私のコードは次のようになります。
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
fig = plt.figure()
ax = plt.subplot(111)
ax.set_ylabel("y-label")
for i in xrange(5):
ax.plot(x, i * x, label='$y = %ix$' % i)
ax.legend()
#change dimension of figure for print
#clone fig displayed
print_fig = fig
print_fig.set_size_inches(7,3)
print_fig.savefig('print_fig.png')
plt.show()
これは私の画面がどのように見えるかです: