当前位置:网站首页>Seaborn draws 11 histograms
Seaborn draws 11 histograms
2022-07-05 16:21:00 【Junhong's road of data analysis】
This article introduces how to use seaborn To draw various histogram
Basic histogram
Horizontal histogram
Title Setting
be based on DataFrame mapping
hue Parameter setting
Color treatment
Multidimensional processing
One I like very much Seaborn Drawn graphics :
Import library
Seaborn yes matplotlib The advanced packaging of , therefore matplotlib You still need to import at the same time :
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')
Import built-in data
It uses seaborn A built-in consumption tips Data sets :
In [2]:
tips = sns.load_dataset("tips")
tips.head()
Basic histogram
In [3]:
x = ["A","B","C"]
y = [1, 2, 3]
sns.barplot(x, y)
plt.show()
Draw a horizontal histogram :
# Horizontal histogram
x = ["A","B","C"]
y = [1, 2, 3]
sns.barplot(y, x)
plt.show()
Set title
In [14]:
x = ["A","B","C"]
y = [1, 2, 3]
fig = sns.barplot(x, y)
fig.set_title('title of seaborn')
plt.show()
Appoint x-y-data
In [5]:
# adopt DataFrame To specify the
ax = sns.barplot(x="day", y="tip", data=tips)
plt.show()
hue Parameters
Implemented grouped display data
In [6]:
ax = sns.barplot(x="day",
y="total_bill",
hue="sex",
data=tips)
Horizontal histogram
In [7]:
ax = sns.barplot(x="total_bill",
y="day",
data=tips)
Custom order
In [8]:
ax = sns.barplot(x="total_bill",
y="day",
# add to order Parameters , order of appointment
order=["Sat","Fri","Sun","Thur"], # Customize
data=tips)
Color treatment
Use a color
In [9]:
ax = sns.barplot(x="size",
y="total_bill",
data=tips,
color="salmon",
saturation=.5)
Color gradient
In [10]:
ax = sns.barplot(x="size",
y="tip",
data=tips,
palette="Blues")
Multidimensional grouping
In [11]:
g = sns.catplot(x="sex",
y="total_bill",
hue="smoker",
col="time",
data=tips,
kind="bar",
height=4,
aspect=.7)
True/False grouping
In [12]:
tips["weekend"] = tips["day"].isin(["Sat", "Sun"])
tips
Out[12]:
In [13]:
ax = sns.barplot(x="day",
y="tip",
hue="weekend",
data=tips,
dodge=False)
- END -
边栏推荐
- 17. [stm32] use only three wires to drive LCD1602 LCD
- 五种常见的咨询公司谈判策略以及如何维护自己的利益
- Cartoon: what is MapReduce?
- Intelligent metal detector based on openharmony
- 一文带你吃透js处理树状结构数据的增删改查
- Clock switching with multiple relationship
- How to use FRP intranet penetration +teamviewer to quickly connect to the intranet host at home when mobile office
- Cs231n notes (medium) -- applicable to 0 Foundation
- 阿掌的怀念
- Defining strict standards, Intel Evo 3.0 is accelerating the upgrading of the PC industry
猜你喜欢
RLock锁的使用
17.[STM32]仅用三根线带你驱动LCD1602液晶
Today's sleep quality record 79 points
Verilog realizes the calculation of the maximum common divisor and the minimum common multiple
DeSci:去中心化科学是Web3.0的新趋势?
21. [STM32] I don't understand the I2C protocol. Dig deep into the sequence diagram to help you write the underlying driver
ES6 deep - ES6 class class
The database of the server is not connected to 200310060 "unknown error" [the service is up, the firewall is off, the port is on, and the netlent port is not connected]
18.[stm32] read the ROM of DS18B20 temperature sensor and realize multi-point temperature measurement
ES6深入—async 函数 与 Symbol 类型
随机推荐
漫画:什么是分布式事务?
2020-2022两周年创作纪念日
研发效能度量指标构成及效能度量方法论
vlunhub- BoredHackerBlog Moriarty Corp
Single merchant v4.4 has the same original intention and strength!
阿掌的怀念
写单元测试的时候犯的错
verilog实现计算最大公约数和最小公倍数
Defining strict standards, Intel Evo 3.0 is accelerating the upgrading of the PC industry
漫画:什么是八皇后问题?
Relationship between objects and classes
开发中Boolean类型使用遇到的坑
单商户 V4.4,初心未变,实力依旧!
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
后台系统发送验证码功能
[graduation season] as a sophomore majoring in planning, I have something to say
不敢买的思考
10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
我们为什么要学习数学建模?
Quick completion guide for manipulator (IX): forward kinematics analysis