import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas import Series, DataFrame
%matplotlib inline
import seaborn as sns
# 使用matplotlib
s1 = Series(np.random.randn(1000))
plt.hist(s1)
(array([ 6., 33., 98., 154., 230., 218., 163., 61., 29., 8.]),
array([-2.96113056, -2.35197999, -1.74282942, -1.13367884, -0.52452827,
0.08462231, 0.69377288, 1.30292346, 1.91207403, 2.52122461,
3.13037518]),
<a list of 10 Patch objects>)
![这里写图片描述](https://img-blog.csdn.net/20180721160403550?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zOTc3ODU3MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
s1.plot(kind='kde')
<matplotlib.axes._subplots.AxesSubplot at 0x277853b9a20>
Seaborn
# 同时绘制密度图和直方图
sns.distplot(s1, hist=True, kde=True)
<matplotlib.axes._subplots.AxesSubplot at 0x277853b9a20>
sns.distplot(s1, hist=True, kde=False, rug=True)
<matplotlib.axes._subplots.AxesSubplot at 0x277859199e8>
sns.distplot(s1, bins=20, hist=True, kde=False, rug=True, color='k')
# 绘制密度图的另一种方法,shada阴影填充
sns.kdeplot(s1, shade=True, color='r')