pythonで散布図行列
pandasを使用して散布図行列や箱ひげを書いてみる。
データはirisを使用。
https://raw.github.com/pydata/pandas/master/pandas/tests/data/iris.csv
(日本語環境テストのため、Nameを種類、lengthを長さ、widthを幅に置換して使用)
前提条件のmatplotlib日本語環境はこちら http://tatabox.hatenablog.com/entry/2013/07/21/025603
# -*- coding: cp932 -*- import pandas as pd import numpy as np from pandas.tools.plotting import radviz '''matplotlibの日本語環境''' from matplotlib import rcParams rcParams['font.family'] = 'IPAexGothic' rcParams['font.sans-serif'] = ['IPAexGothic'] import matplotlib.pyplot as plt '''データの読み込み。Windows環境はencoding='cp932'必須''' iris = pd.read_csv('.//iris.csv',index_col=0,encoding='cp932') '''最初の5つを表示''' print iris.head(n=5) '''概要''' print iris.describe() '''相関係数行列とCSV出力''' iris_corr=iris.corr() print iris_corr iris_corr.to_csv('iris_corr.csv') '''散布図行列''' pd.scatter_matrix(iris,color='green',diagonal='kde',figsize=(6,6)) '''radviz''' plt.figure() radviz(iris,u"種類") '''箱ひげ''' iris.boxplot(by=u"種類") plt.show()
[
他だとpyvttblが良さそう。
https://pyvttbl.googlecode.com/hg-history/0315dcd0bc2fba044fae4449dc9d84f5fc7b66eb/doc/_build/html/scatter_matrix.html
参考
http://blog.livedoor.jp/norikazu197768/archives/12539634.html
http://pandas.pydata.org/pandas-docs/stable/visualization.html (公式)