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

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

# 数据集中变量间关系可视化
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>
 
相关文章
相关标签/搜索