matplotlibで出力される画像のサイズを変更する

matplotlib.pyplot.figure関数を使う。

matplotlib.pyplot.figure(figsize=(横インチ, 縦インチ), dpi=解像度, facecolor=グラフの余白色, edgecolor=’k’)

※numというパラメータ引数もあるようだが、使い方がよくわからない

ビットカジノ

■サンプルスクリプト

import numpy as np
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 11, 23, 45, 21]

plt.figure(figsize=(4, 4), dpi=50)
plt.bar(x, y)
plt.savefig('bar_basic.png')
plt.show()

(実効結果)