In [12]:
import numpy as np
from numpy.random import randn
import pandas as pd

from scipy import stats

import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline
In [16]:
# 英語のページですが・・・
url = 'http://en.wikipedia.org/wiki/Box_plot#mediaviewer/File:Boxplot_vs_PDF.svg'

data1 = randn(100)
data2 = randn(100) + 2 # Off set the mean
In [21]:
sns.distplot(data1)
sns.distplot(data2)
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x10af75ba8>
In [29]:
# boxplotを作ります。
sns.boxplot(data=[data1,data2])
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x10c69a2b0>
In [30]:
# 外れ値を含むことができます。
sns.boxplot(data=[data1,data2],whis=np.inf)
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x10c903b38>
In [33]:
# 水平に並べることもできます。
sns.boxplot(data=[data1,data2],whis=np.inf, orient = 'h')
Out[33]:
<matplotlib.axes._subplots.AxesSubplot at 0x10c95f630>
In [34]:
# Violin/Viola plot はbox plotのシンプルさとKDEの情報量を兼ね備えます。
In [42]:
# 正規分布に従う乱数です。
data1 = stats.norm(0,5).rvs(100)

# γ分布に従う乱数を生成します。
data2 = np.concatenate([stats.gamma(5).rvs(50)-1,
                        -1*stats.gamma(5).rvs(50)])

sns.boxplot(data=[data1,data2],whis=np.inf)
Out[42]:
<matplotlib.axes._subplots.AxesSubplot at 0x10d29e2e8>
In [43]:
# ヴァイオリンプロットを描くと違いが分かります。
sns.violinplot(data =[data1,data2])
Out[43]:
<matplotlib.axes._subplots.AxesSubplot at 0x10d6856a0>
In [45]:
# バンド幅を細かくしてみましょう。
sns.violinplot(data=data2,bw=0.01)
Out[45]:
<matplotlib.axes._subplots.AxesSubplot at 0x10d7946d8>
In [47]:
# rugプロットと同じような機能もあります。
sns.violinplot(data=data1,inner="stick")
Out[47]:
<matplotlib.axes._subplots.AxesSubplot at 0x10e521c18>