import seaborn as snshtml
import pandas as pddom
np.random.seed(100)
v1 = pd.Series(np.random.normal(0, 10, 1000), name='v1')
v2 = pd.Series(2 * v1 + np.random.normal(60, 15, 1000), name='v2')orm
# 經過matplotlib繪圖
plt.figure()
plt.hist(v1, alpha=0.7, bins=np.arange(-50, 150, 5), label='v1')
plt.hist(v2, alpha=0.7, bins=np.arange(-50, 150, 5), label='v2')
plt.legend()htm
<matplotlib.legend.Legend at 0x1a16b1ca90>
plt.figure()
plt.hist([v1, v2], histtype='barstacked', normed=True)
v3 = np.concatenate((v1, v2))
sns.kdeplot(v3)ip
<matplotlib.axes._subplots.AxesSubplot at 0x1a16a2b128>
# 使用seaborn繪圖
plt.figure()
sns.distplot(v3)pandas
<matplotlib.axes._subplots.AxesSubplot at 0x1a16a0bdd8>
# 使用seaborn繪圖
plt.figure()
sns.jointplot(v1, v2, alpha=0.4)it
<seaborn.axisgrid.JointGrid at 0x1a170d59b0>
<Figure size 432x288 with 0 Axes>
# 使用seaborn繪圖
plt.figure()
grid = sns.jointplot(v1, v2, alpha=0.4)#散佈圖
grid.ax_joint.set_aspect('equal')io
<Figure size 432x288 with 0 Axes>
plt.figure()
sns.jointplot(v1, v2, kind='hex')#二維直方圖class
<IPython.core.display.Javascript object>
plt.figure()
sns.jointplot(v1, v2, kind='kde')#核密度估計import
<seaborn.axisgrid.JointGrid at 0x1a17297978>
<Figure size 432x288 with 0 Axes>
iris = pd.read_csv('iris.csv')
iris.head()
![](http://static.javashuo.com/static/loading.gif)
# 數據集中變量間關係可視化
sns.pairplot(iris, hue='Name', diag_kind='kde')
<IPython.core.display.Javascript object>
plt.figure()
plt.subplot(121)
sns.swarmplot('Name', 'PetalLength', data=iris)
plt.subplot(122)
sns.violinplot('Name', 'PetalLength', data=iris)
<IPython.core.display.Javascript object>