1. 学ぶ
  2. /
  3. コース
  4. /
  5. R ユーザーのための Python

Connected

演習

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()

指示1 / 2

undefined XP
    1
    2
  • 軸が1つの図を作成します。
  • ax 軸オブジェクトを使って、'tip' 列と 'total_bill' 列の散布図を描画しましょう。