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

# scipyの統計パッケージも使います。
from scipy import stats

# 描画のためのライブラリです。
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

# ブラウザ内に画像を埋め込むための命令です
%matplotlib inline

ヒストグラムの説明は以下を参照してください。 https://ja.wikipedia.org/wiki/%E3%83%92%E3%82%B9%E3%83%88%E3%82%B0%E3%83%A9%E3%83%A0

In [2]:
# 正規分布に従う乱数を作ります。
dataset1 = randn(100)
# bins=10がデフォルトです。
plt.hist(dataset1)
Out[2]:
(array([  9.,  10.,   8.,   8.,  15.,  15.,  12.,  11.,   7.,   5.]),
 array([-1.7284242 , -1.35861471, -0.98880522, -0.61899573, -0.24918624,
         0.12062325,  0.49043274,  0.86024223,  1.23005172,  1.59986121,
         1.9696707 ]),
 <a list of 10 Patch objects>)
In [3]:
# もう一つ作ります。
dataset2 = randn(80)
# 色を変えてみましょう。
plt.hist(dataset2,color='indianred')
Out[3]:
(array([  3.,   4.,   7.,  16.,  15.,  19.,   9.,   3.,   3.,   1.]),
 array([-2.33418641, -1.84911347, -1.36404053, -0.87896759, -0.39389465,
         0.09117829,  0.57625123,  1.06132417,  1.54639711,  2.03147005,
         2.51654299]),
 <a list of 10 Patch objects>)
In [4]:
plt.hist(dataset1, normed=True)
Out[4]:
(array([ 0.24336855,  0.2704095 ,  0.2163276 ,  0.2163276 ,  0.40561425,
         0.40561425,  0.3244914 ,  0.29745045,  0.18928665,  0.13520475]),
 array([-1.7284242 , -1.35861471, -0.98880522, -0.61899573, -0.24918624,
         0.12062325,  0.49043274,  0.86024223,  1.23005172,  1.59986121,
         1.9696707 ]),
 <a list of 10 Patch objects>)
In [ ]:
 
In [7]:
# We can use normed to plot on same plot

# Set normed=True for the plots to be normalized in order to comapre data sets with different number of observations
# Set alpha=0.5 for transperancy

plt.hist(dataset1,normed=True,alpha=0.5,bins=20)
plt.hist(dataset2,normed=True,alpha=0.5,bins=20, color='indianred')
Out[7]:
(array([ 0.10307728,  0.05153864,  0.05153864,  0.15461592,  0.10307728,
         0.2576932 ,  0.36077049,  0.46384777,  0.20615456,  0.56692505,
         0.30923184,  0.67000233,  0.20615456,  0.2576932 ,  0.15461592,
         0.        ,  0.10307728,  0.05153864,  0.        ,  0.05153864]),
 array([-2.33418641, -2.09164994, -1.84911347, -1.606577  , -1.36404053,
        -1.12150406, -0.87896759, -0.63643112, -0.39389465, -0.15135818,
         0.09117829,  0.33371476,  0.57625123,  0.8187877 ,  1.06132417,
         1.30386064,  1.54639711,  1.78893358,  2.03147005,  2.27400652,
         2.51654299]),
 <a list of 20 Patch objects>)
In [5]:
data1 = randn(1000)
data2 = randn(1000)

# 同時分布(結合分布)
sns.jointplot(data1,data2)
Out[5]:
<seaborn.axisgrid.JointGrid at 0x109d4b978>
In [6]:
# もうすこし分かり易く
sns.jointplot(data1,data2,kind='hex')
Out[6]:
<seaborn.axisgrid.JointGrid at 0x109d4dd68>