1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pandasで散布図行列(Scatter matrix)を描く

Last updated at Posted at 2022-03-18

散布図行列の描き方

下図のように各量を比較した散布図とヒストグラムをまとめて描ける。
scatter_matrix.png

scatter_matrix.py
#インポート
import pandas as pd
import matplotlib.pyplot as plt

#irisデータセットの読み込み
from sklearn.datasets import load_iris
iris_dataset = load_iris()
X_iris = pd.DataFrame(iris_dataset['data'], columns=iris_dataset.feature_names) #説明変数 DataFrame型
y_iris = iris_dataset['target'] #目的変数 3種類に分けられる

#散布図行列の描画
plt.figure() #グラフを描く領域の作成
scatter_matrix = pd.plotting.scatter_matrix(
    X_iris, #説明変数
    c = y_iris, #目的変数ごとに色分け
    figsize = (10, 10), #図の大きさ
    marker = 'o', #マーカーの種類
    hist_kwds = {'bins': 20}, #ヒストグラムの分割数
    edgecolors='black'
)
plt.savefig('scatter_matrix.png') #図の保存

参考

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?