Python数据分析~seaborn数据可视化


import seaborn as sns

import pandas as pd

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')

# 通过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()

<matplotlib.legend.Legend at 0x1a16b1ca90>
 

plt.figure()
plt.hist([v1, v2], histtype='barstacked', normed=True)
v3 = np.concatenate((v1, v2))
sns.kdeplot(v3)

<matplotlib.axes._subplots.AxesSubplot at 0x1a16a2b128>
 

# 使用seaborn绘图
plt.figure()
sns.distplot(v3)

<matplotlib.axes._subplots.AxesSubplot at 0x1a16a0bdd8>
 

# 使用seaborn绘图
plt.figure()
sns.jointplot(v1, v2, alpha=0.4)

<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')

<Figure size 432x288 with 0 Axes>
 

plt.figure()
sns.jointplot(v1, v2, kind='hex')#二维直方图

<IPython.core.display.Javascript object>
 

plt.figure()
sns.jointplot(v1, v2, kind='kde')#核密度估计

<seaborn.axisgrid.JointGrid at 0x1a17297978>
 
<Figure size 432x288 with 0 Axes>
 

iris = pd.read_csv('iris.csv')
iris.head()

# 数据集中变量间关系可视化
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>
 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM