23
23

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 5 years have passed since last update.

pythonで散布図行列を描く

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
23
0

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
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?