VOOZH about

URL: https://qiita.com/sz_dr/items/4b9fae1052e40122725c

⇱ pythonで散布図行列を描く #Python - Qiita


👁 Image
23

Go to list of users who liked

22

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

pythonで散布図行列を描く

23
Posted at

概要

Rで散布図行列を描くときはpairs関数を使います.

pairs(iris[1:4],main="Edgar Anderson's Iris Data",pch=21,bg=c("red","green3","blue")[unclass(iris$Species)])

👁 rmatrix.png

これをpythonで描こうとしたのですが,お馴染みのmatplotlibには散布図行列を描く関数が実装されていないようです.

自分でsubplotを駆使して実装しても良いのですが,ここではseabornというグラフ描画ライブラリを使って散布図行列を描く方法を紹介します.

Dependency

matplotlib (>=1.4)
seaborn (>=0.5)
どちらもpipでインストールできるはずです.

ソースコード

import matplotlib.pyplot as plt
import seaborn as sns

df = sns.load_dataset("iris")
sns.pairplot(df, hue="species", size=2.5)
plt.show()

実行結果

👁 figure_1.png

その他

seabornには他にも様々なカッコいいグラフを描くためのツールがあります.
matplotlibのグラフに飽きた方はぜひ使ってみてください.

参考

Scatterplot Matrix

23

Go to list of users who liked

22
0

Go to list of comments

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
23

Go to list of users who liked

22