可视化seaborn(4)

写在前面的准备工作

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import numpy as np
import pandas as pd

plt.rcParams['font.sans-serif'] = ['SimHei']  #用来正常显示中文标签 
plt.rcParams['axes.unicode_minus'] = False   #用来正常显示负号  
sns.set_style('darkgrid',{'font.sans-serif':['SimHei','Arial']})

import warnings  #去除部分警告信息
warnings.filterwarnings('ignore')

sns.set() #返回seaborn的默认设置

柱状图

x = ['a','b','c','d']
y = [164, 56, 126, 56]
sns.barplot(x,y)

可视化seaborn(4)

#条形图   orient表示倒置, saturation是颜色深度
sns.barplot(y,x,order = ['b','d','c','a'],orient='h',saturation=1)
tips = sns.load_dataset("tips")
sns.barplot(x = 'day', y = 'tip', data = tips)
#柱子的高是平均值,黑线是置信区间

可视化seaborn(4)

sns.barplot(x = 'day', y = 'tip', data = tips, hue = 'sex', palette = 'Greens')

可视化seaborn(4)

条形图

#条形图
sns.barplot(y = 'day',x = 'total_bill',data = tips)

可视化seaborn(4)

箱线图

L = [3,5,1,4,8]
sns.boxplot( y = L)

可视化seaborn(4)

sns.boxplot(x ='day',y = 'tip',data = tips)

可视化seaborn(4)

sns.boxplot(x ='day',y = 'tip',data = tips,hue = 'sex')

可视化seaborn(4)

小提琴图 是箱线图和密度图的结合

L = [3,2,0,1,1]
sns.violinplot(L)

可视化seaborn(4)

L = [3,2,0,1,1]
sns.violinplot( y = L)

可视化seaborn(4)

sns.violinplot(x = 'day',y = 'tip',hue = 'sex',data = tips)

可视化seaborn(4)

sns.violinplot(x = 'day',y = 'tip',hue = 'sex',data = tips,split = True)

可视化seaborn(4)

分类散点图----Strip(带状)和Swarm(蜂群)

sns.stripplot(x = 'day', y ='tip', data= tips)

可视化seaborn(4)

sns.stripplot(x = 'day', y ='tip',hue = 'sex', data= tips)

可视化seaborn(4)

sns.swarmplot(x = 'day', y ='tip', data= tips)

可视化seaborn(4)

sns.swarmplot(x = 'day', y ='tip',hue = 'sex' ,data= tips)

可视化seaborn(4)

分面网格分类图 (FacetGrid)

sns.catplot(x = 'day', y ='tip',hue = 'sex' ,col = 'time',kind = "violin",row = 'smoker',data= tips)

可视化seaborn(4)

sns.catplot(x = 'day', y ='tip',hue = 'sex' ,col = 'time',kind = "violin",data= tips, split = True) #图形各一半的合并

可视化seaborn(4)

sns.catplot()

sns.catplot(x = 'day', y ='tip',hue = 'sex' ,col = 'size',kind = "bar",data= tips)

可视化seaborn(4)

sns.catplot(x = 'day', y ='tip',hue = 'sex' ,col = 'size',col_wrap = 3,kind = "bar",data= tips)

可视化seaborn(4)

散点图

n = 1024
x = np.random.normal(0,1,n)
y = np.random.normal(0,1,n)
sns.scatterplot(x = x, y = y)
plt.title('绘制散点图',fontproperties = 'SimHei')

可视化seaborn(4)

sns.scatterplot(x = 'total_bill', y = 'tip', hue = 'sex',data = tips)

可视化seaborn(4)

plt.figure(dpi =150)
sns.scatterplot(x = 'total_bill', y = 'tip', hue = 'sex',style = 'time',size = 'size',data = tips)

可视化seaborn(4)

上一篇:chrome devtools tip(2)--自定义代码片段,构建你的工具箱


下一篇:layer实现鼠标悬浮效果