Travel Tips
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
分类数据可视化 - 分类散点图 stripplot() / swarmplot()
stripplot() / swarmplot()
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline sns.set_style("whitegrid") sns.set_context("paper") # 设置风格、尺度 import warnings warnings.filterwarnings('ignore') # 不发出警告
# 按照不同类别对样本数据进行分布散点图绘制
tips = sns.load_dataset("tips") print(tips.head()) # 加载数据 print(tips['day'].value_counts())
sns.stripplot(x="day", # x → 设置分组统计字段 y="total_bill", # y → 数据分布统计字段 # 这里xy数据对调,将会使得散点图横向分布 data=tips, # data → 对应数据 jitter = True, # jitter → 当点数据重合较多时,用该参数做一些调整,也可以设置间距如:jitter = 0.1 size = 6, edgecolor = 'w',linewidth=1,marker = 'o' # 设置点的大小、描边颜色或宽度、点样式 )
# 通过hue参数再分类
sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
# 设置调色盘
sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True, palette="Set2", # 设置调色盘 dodge=True, # 是否拆分 )
# 筛选分类类别
print(tips['day'].value_counts()) # 查看day字段的唯一值 sns.stripplot(x="day", y="total_bill", data=tips,jitter = True, order = ['Sat','Sun']) # order → 筛选类别
# 分簇散点图
sns.swarmplot(x="total_bill", y="day", data=tips, size = 5, edgecolor = 'w',linewidth=1,marker = 'o', palette = 'Reds') # 用法和stripplot类似
sns.swarmplot(x="sex", y="total_bill", hue="day", data=tips)
sns.swarmplot(x="sex", y="total_bill", hue="day", data=tips, palette="Set2", # 设置调色盘 dodge=True, # 是否拆分 )
print(tips['day'].value_counts()) # 查看day字段的唯一值 sns.swarmplot(x="day", y="total_bill", data=tips, order = ['Sat','Sun']) # order → 筛选类别
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Donec in ullamcorper quam. Aenean vel nibh eu magna gravida fermentum. Praesent eget nisi pulvinar, sollicitudin eros vitae, tristique odio.
December 4, 2020 at 3:12 pm
我是 s enim interduante quis metus. Duis porta ornare nulla ut bibendum
Rosie
6 minutes ago