当前位置:网站首页>Seaborn绘制11个柱状图
Seaborn绘制11个柱状图
2022-07-05 15:43:00 【俊红的数据分析之路】
本文介绍的是如何使用seaborn来绘制各种柱状图
基础柱状图
水平柱状图
标题设置
基于DataFrame绘图
hue参数设置
颜色处理
多维度处理
个人很喜欢的一个Seaborn绘制的图形:

导入库
Seaborn是matplotlib的高级封装,所以matplotlib还是要同时导入:
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set_theme(style="whitegrid")
sns.set_style('darkgrid')导入内置数据
使用的是seaborn中内置的一份消费tips数据集:
In [2]:
tips = sns.load_dataset("tips")
tips.head()
基础柱状图
In [3]:
x = ["A","B","C"]
y = [1, 2, 3]
sns.barplot(x, y)
plt.show()
绘制水平柱状图:
# 水平柱状图
x = ["A","B","C"]
y = [1, 2, 3]
sns.barplot(y, x)
plt.show()
设置标题
In [14]:
x = ["A","B","C"]
y = [1, 2, 3]
fig = sns.barplot(x, y)
fig.set_title('title of seaborn')
plt.show()
指定x-y-data
In [5]:
# 通过DataFrame来指定
ax = sns.barplot(x="day", y="tip", data=tips)
plt.show()
hue参数
实现的分组显示数据
In [6]:
ax = sns.barplot(x="day",
y="total_bill",
hue="sex",
data=tips)
水平柱状图
In [7]:
ax = sns.barplot(x="total_bill",
y="day",
data=tips)
自定义顺序
In [8]:
ax = sns.barplot(x="total_bill",
y="day",
# 添加order参数,指定顺序
order=["Sat","Fri","Sun","Thur"], # 自定义
data=tips)
颜色处理
使用一种颜色
In [9]:
ax = sns.barplot(x="size",
y="total_bill",
data=tips,
color="salmon",
saturation=.5)
颜色渐变
In [10]:
ax = sns.barplot(x="size",
y="tip",
data=tips,
palette="Blues")
多维分组
In [11]:
g = sns.catplot(x="sex",
y="total_bill",
hue="smoker",
col="time",
data=tips,
kind="bar",
height=4,
aspect=.7)
True/False分组
In [12]:
tips["weekend"] = tips["day"].isin(["Sat", "Sun"])
tipsOut[12]:

In [13]:
ax = sns.barplot(x="day",
y="tip",
hue="weekend",
data=tips,
dodge=False)
- END -边栏推荐
- Data communication foundation - dynamic routing protocol rip
- Cs231n notes (medium) -- applicable to 0 Foundation
- APICloud云调试解决方案
- 利用GrayLog告警功能实现钉钉群机器人定时工作提醒
- Basic JSON operations of MySQL 5.7
- OceanBase社区版之OBD方式部署方式本地安装
- EDI许可证和ICP经营性证有什么区别
- Li Kou today's question -729 My schedule I
- ES6深入—ES6 Generator 函数
- Mongodb getting started Tutorial Part 04 mongodb client
猜你喜欢

SQL injection sqllabs (basic challenges) 1-10

Codasip为RISC-V处理器系列增加Veridify安全启动功能
![17.[STM32]仅用三根线带你驱动LCD1602液晶](/img/c6/b56c54da2553a451b526179f8b5867.png)
17.[STM32]仅用三根线带你驱动LCD1602液晶

Five common negotiation strategies of consulting companies and how to safeguard their own interests

五种常见的咨询公司谈判策略以及如何维护自己的利益

list去重并统计个数

Vulnhub-Moneybox

Analytic hierarchy process of mathematical modeling (including Matlab code)

vant tabbar遮挡内容的解决方式
![21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动](/img/f4/2c935dd9933f5cd4324c29c41ab221.png)
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
随机推荐
漫画:什么是八皇后问题?
Noi / 1.5 37: mercenaries
记一次'非常诡异'的云安全组规则问题排查过程
践行自主可控3.0,真正开创中国人自己的开源事业
Data communication foundation smart_ Link_&_ Monitor_ Link
具有倍数关系的时钟切换
Arduino controls a tiny hexapod 3D printing robot
Research and development efficiency measurement index composition and efficiency measurement methodology
项目sql中批量update的时候参数类型设置错误
Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
vant popup+其他组件的组合使用,及避坑指南
Memo 00
英特尔第13代Raptor Lake处理器信息曝光:更多核心 更大缓存
Query the latest record in SQL
Data communication foundation - dynamic routing protocol rip
18.[STM32]读取DS18B20温度传感器的ROM并实现多点测量温度
Data communication foundation - routing communication between VLANs
Interval DP (gravel consolidation)
vlunhub- BoredHackerBlog Social Network
Intelligent metal detector based on openharmony