Help us understand the problem. What is going on with this article?

pythonで散布図行列を描く

More than 5 years have passed since last update.

概要

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

sz_dr
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした