1.直方圖+密度圖
s = pd.Series(np.random.randn(1000))
s.hist(bins = 20,
histtype = 'bar',
align = 'mid',
orientation = 'vertical',
alpha=0.5,
normed =True)
# bin:箱子的寬度
# normed 標準化,配合密度圖
# histtype 風格,bar,barstacked,step,stepfilled
# orientation 水平還是垂直{‘horizontal’, ‘vertical’}
# align : {‘left’, ‘mid’, ‘right’}, optional(對齊方式)
s.plot(kind='kde',style='k--')
# 密度圖
2.堆疊直方圖:plt.plot.hixt(stacked=True)
plt.figure(num=1)
df = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
'c': np.random.randn(1000) - 1, 'd': np.random.randn(1000)-2},
columns=['a', 'b', 'c','d'])
df.plot.hist(stacked=True,
bins=20,
colormap='Greens_r',
alpha=0.5,
grid=True)
# 使用DataFrame.plot.hist()和Series.plot.hist()方法繪製
# stacked:是否堆疊
df.hist(bins=50)
# 生成多個直方圖