Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
22
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@sz_dr

pythonで散布図行列を描く

概要

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
22
Help us understand the problem. What are the problem?