始める無料で始める

matplotlib のサブ図

複数のサブプロットを1つの図にまとめたい場合があります。

plot.subplots() 関数を使うと、図(figure)と軸(axes)を同時に作成できます。 この関数は figure オブジェクトと axes オブジェクトを返します。

import matplotlib.pyplot as plt

# Create a figure and axes 
fig, (ax1, ax2) = plt.subplots(number_of_rows, number_of_columns)

これらの axes オブジェクトを使って、グラフを描画できます。

# Use the axes to plot visualizations
ax1.hist(df['column_1'])
ax2.hist(df['column_2'])
plt.show()

この演習はコースの一部です

R ユーザーのための Python

コースを見る

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

import matplotlib.pyplot as plt

# Create a figure with 1 axes
fig, ax = plt.____(1, 1)

# Plot a scatter plot in the axes
____.scatter(tips____, tips____)
plt.show()
コードを編集して実行