- ✕この概要は、複数のオンライン ソースに基づいて AI を使用して生成されました。元のソース情報を表示するには、[詳細情報] リンクを使用します。
matplotlib.pyplot.subplots()は、グラフ描画の際にFigureとAxesを同時に生成する便利な関数です。この関数を使うことで、複数のサブプロットを簡単に作成し、効率的にグラフを描画できます。
基本的な使い方
plt.subplots()を使用すると、1つのFigureとAxesを生成します。以下は基本的な例です。
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 100)y = x**2# FigureとAxesを生成fig, ax = plt.subplots()ax.plot(x, y)ax.set_title("単一のプロット")plt.show()コピーしました。✕コピーこのコードでは、1つのサブプロットを作成し、二次関数のグラフを描画しています。
複数のサブプロットを作成
plt.subplots()にnrowsとncolsを指定することで、複数のサブプロットを作成できます。
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 6), tight_layout=True)# 各サブプロットに異なるデータを描画x = np.linspace(0, 2 * np.pi, 100)axes[0, 0].plot(x, np.sin(x))axes[0, 0].set_title("sin(x)")axes[0, 1].plot(x, np.cos(x))axes[0, 1].set_title("cos(x)")axes[1, 0].plot(x, np.sin(2 * x))axes[1, 0].set_title("sin(2x)")axes[1, 1].plot(x, np.cos(2 * x))axes[1, 1].set_title("cos(2x)")plt.show()コピーしました。✕コピーこのコードでは、2×2のグリッドに4つのサブプロットを配置しています。
軸の共有
sharexやshareyを指定すると、サブプロット間で軸を共有できます。
Matplotlib plt.subplots ()の使い方|FigureとAxesを同時生成!
matplotlib.pyplot.subplots — Matplotlib 3.10.8 …
When subplots have a shared x-axis along a column, only the x tick labels of the bottom subplot are created. Similarly, when subplots have a shared y-axis along …
plt.subplots を使用して複数のサブプロットを作成する_Matplotlib ...
Matplotlib subplot に (a), (b), (c)… を自動配置する論文向け関数例
2025年7月14日 · Python の可視化ライブラリ Matplotlib で論文用の図を作成する際、subplot に (a), (b), (c) といったラベルを配置するのは一般的です。 しかし、Matplotlib の plt.subplots で subplot を並べ …
Matplotlib サブプロット:plt.subplots () でマルチパネル図を作成
2026年2月9日 · Matplotlibの plt.subplots() 関数は、共有軸、一貫したサイズ設定、柔軟なレイアウトを持つマルチパネル図を作成します。 このガイドでは、基本的なグリッドから高度な非対称レイアウ …
matplotlib – subplots でグリッド上に図を作成する方法 …
matplotlib の pyplot.subplots(), Figure.add_subplots() を使用して、グリッド上の Axes を作成する方法について解説します。 matplotlib において、Figure の中に …
- 他の人も質問しています
Create multiple subplots using plt.subplots — Matplotlib …
Create multiple subplots using plt.subplots # pyplot.subplots creates a figure and a grid of subplots with a single call, while providing reasonable control over how …
Matplotlib で複数のサブプロットを作成する | LabEx
Matplotlib のサブプロットを使用して、単一の図内で複数のプロットを作成および管理する方法を学びます。 この実験では、軸の作成、データのプロット、レ …
subplot? add_subplot? subplots? #Python - Qiita
2021年3月13日 · はじめに 今回はpythonのライブラリであるmatplotlibを使用した際にsubplot,subplots,plotなどで詰まったためそれらの違いを話していこうと思います。 1.plt.figure () …
[matplotlib] 10. Matplotlibで複数のグラフを表示する方 …
2019年2月20日 · Matplotlibで複数グラフを効率的に配置・表示する方法を解説。 subplot、add_subplot、subplots、GridSpecなどの手法を使って、1つのウィン …