-
seaborn学习笔记(四):箱型图、小提琴图
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [3]:
tips = sns.load_dataset("tips")
In [4]:
tips.head(2)
Out[4]:
In [5]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('x="day", y="total_bill"')
pic = sns.boxplot(x="total_bill", y="day", data=tips, ax=ax[1])
pic.set_title('x="total_bill", y="day"')
Out[5]:
In [18]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0], hue="smoker")
pic.set_title('hue="smoker"')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[1], hue="smoker", dodge=False)
pic.set_title('hue="smoker", dodge=False')
Out[18]:
In [8]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default order')
pic = sns.boxplot(x="day", y="total_bill", data=tips, order=['Sun', 'Sat', 'Thur', 'Fri'], ax=ax[1])
pic.set_title('"Sun", "Sat", "Thur", "Fri"')
Out[8]:
In [11]:
ax = sns.boxplot(x="day", y="total_bill", data=tips, color="red")
In [12]:
ax = sns.boxplot(x="day", y="total_bill", data=tips, color="red",saturation=0.5 )
In [15]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default width')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[1], width=0.5)
pic.set_title('width=0.5')
Out[15]:
In [23]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default fliersize: 5')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[1], fliersize=1)
pic.set_title('fliersize=1')
Out[23]:
In [28]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default linewidth')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[1], linewidth=1)
pic.set_title('linewidth=1')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[2], linewidth=5)
pic.set_title('linewidth=5')
Out[28]:
In [30]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(8, 3))
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default whis: 1.5')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[1], whis=2)
pic.set_title('whis=2')
pic = sns.boxplot(x="day", y="total_bill", data=tips, ax=ax[2], whis=3)
pic.set_title('whis=3')
Out[30]:
In [53]:
_ = sns.boxenplot(x="day", y="total_bill", data=tips)
In [59]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('x="day", y="total_bill"')
pic = sns.violinplot(x="total_bill", y="day", data=tips, ax=ax[1])
_ = pic.set_title('x="total_bill", y="day"')
In [60]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0], hue="smoker")
pic.set_title('hue="smoker"')
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[1], hue="smoker", dodge=False)
_ = pic.set_title('hue="smoker", dodge=False')
In [61]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default order')
pic = sns.violinplot(x="day", y="total_bill", data=tips, order=['Sun', 'Sat', 'Thur', 'Fri'], ax=ax[1])
_ = pic.set_title('"Sun", "Sat", "Thur", "Fri"')
In [63]:
ax = sns.violinplot(x="day", y="total_bill", data=tips, color="red")
In [64]:
ax = sns.violinplot(x="day", y="total_bill", data=tips, color="red",saturation=0.5 )
In [73]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(12, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0], hue="smoker")
pic.set_title('no split')
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[1], hue="smoker", split=True)
pic.set_title('split=True')
Out[73]:
In [70]:
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips, palette="muted", split=True)
In [74]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(8, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default linewidth')
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[1], linewidth=1)
pic.set_title('linewidth=1')
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[2], linewidth=5)
pic.set_title('linewidth=5')
Out[74]:
In [81]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(12, 3))
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default width')
pic = sns.violinplot(x="day", y="total_bill", data=tips, ax=ax[1], width=1)
_ = pic.set_title('width=1')
出处:https://www.cnblogs.com/chenhuabin/p/15925939.html
最新更新
博克-定制图例
博克-注释和图例
Bokeh–添加小部件
向博克图添加标签
将交互式滑块添加到博克图
在 Bokeh 中添加按钮
谷歌、微软、Meta?谁才是 Python 最大的金
Objective-C语法之代码块(block)的使用
URL Encode
go语言写http踩得坑
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
[SQL Server]按照设定的周别的第一天算任意
Linux下定时自动备份Docker中所有SqlServer数
武装你的WEBAPI-OData入门
武装你的WEBAPI-OData便捷查询
武装你的WEBAPI-OData分页查询
武装你的WEBAPI-OData资源更新Delta
5. 武装你的WEBAPI-OData使用Endpoint 05-09
武装你的WEBAPI-OData之API版本管理
武装你的WEBAPI-OData常见问题
武装你的WEBAPI-OData聚合查询
OData WebAPI实践-OData与EDM
OData WebAPI实践-Non-EDM模式