はじめに
簡単かつ簡潔にデータを可視化できるライブラリであるseabornを用いて、データのヒストグラムとそのカーネル密度推定グラフを表示する方法について説明する。
コード

解説
モジュールのインポートなど
データの読み込み
3/8-10の京都と鹿児島の気象データを下記サイトから読み込む。
気象庁|過去の気象データ検索
過去の気象データ検索
DataFrameの結合
pd.concatでデータフレームを結合する。
気温データをヒストグラムを描写するデータとして用いる。
ヒストグラムの表示
sns.distplot(x)でxのヒストグラムが作成できる。カーネル密度推定グラフも同時に表示される。

KDE非表示にしラグを表示
kde=Falseでカーネル密度推定グラフが非表示になり、rug=Trueで横軸下部にデータの値に応じて棒が生える。

ヒストグラムのbin数の変更
binsでbinの数を指定することで変更できる。

ヒストグラムをnormalize
ヒストグラムの累計値を1にするには、norm_hist=Trueとする。

色の変更
color=”r”で色を赤にすることができる。

カーネル密度推定グラフのみを表示
kdeplotを用いることでカーネル密度推定グラフのみを表示できる。shade=Trueのような細かい設定も可能となる。

KDEplotのデータを取得
kdeplotに対して.get_lines()[0].get_data()とすることでプロットされているデータを取得することができる。
コードをダウンロード(.pyファイル) コードをダウンロード(.ipynbファイル)参考
Visualizing distributions of data — seaborn 0.13.2 documentation

Get data points from Seaborn distplot
I use sns.distplot to plot a univariate distribution of observations. Still, I need not only the chart, but also the dat...
コメント