- 最終更新
- 2026/08/17
3秒でわかる
matplotlib で描画用のキャンバスを新しく作る関数。サイズや解像度を指定し、グラフを何枚も別々に描き分けるときの起点になります。
30秒図解
もう少し詳しく
どういうものか
plt.figure はfigsize でdpi で
plt.plot を
なぜ必要か
分析のfigure を
具体例
サイズと
import matplotlib.pyplot as plt
months = ["1月", "2月", "3月", "4月"]
sales = [120, 180, 90, 210]
plt.figure(figsize=(8, 4), dpi=120)
plt.bar(months, sales)
plt.title("月別売上")
plt.ylabel("万円")
plt.savefig("sales.png", bbox_inches="tight")
plt.close()複数枚をfigure と close で
for name, data in groups.items():
plt.figure(figsize=(6, 3))
plt.plot(data)
plt.savefig(f"{name}.png")
plt.close()つまずきやすいところ
plt.show のあとに plt.savefig を
ループで close を
figsize のdpi でfigsize=(10, ...) です。
似た用語との違い
plt.figure は入れ物を1つ作るだけ、plt.subplots はfig と ax の2つを返します。1枚に複数の

