seaborn绘图入门1(lineplot+barplot+heatmap+scatterplot)
发布日期:2021-07-01 03:25:35
浏览次数:2
分类:技术文章
本文共 3470 字,大约阅读时间需要 11 分钟。
文章目录
learn from
下一篇:
1. lineplot 线图
# -*- coding:utf-8 -*-# @Python Version: 3.7# @Time: 2020/5/14 0:10# @Author: Michael Ming# @Website: https://michael.blog.csdn.net/# @File: seabornExercise.py# @Reference: import pandas as pdpd.plotting.register_matplotlib_converters()import matplotlib.pyplot as pltimport seaborn as snsfilepath = "spotify.csv"data = pd.read_csv(filepath, index_col='Date', parse_dates=True)print(data.head()) # 数据头几行print(data.tail()) # 尾部几行print(list(data.columns)) # 列名称print(data.index) # 行index数据plt.figure(figsize=(12, 6))sns.lineplot(data=data) # 单个数据可以加 label="label_test"plt.title("title")plt.xlabel("Data_test")plt.show()sns.lineplot(data=data['Shape of You'],label='Shape of You')plt.show()
Shape of You Despacito ... HUMBLE. UnforgettableDate ... 2017-01-06 12287078 NaN ... NaN NaN2017-01-07 13190270 NaN ... NaN NaN2017-01-08 13099919 NaN ... NaN NaN2017-01-09 14506351 NaN ... NaN NaN2017-01-10 14275628 NaN ... NaN NaN[5 rows x 5 columns] Shape of You Despacito ... HUMBLE. UnforgettableDate ... 2018-01-05 4492978 3450315.0 ... 2685857.0 2869783.02018-01-06 4416476 3394284.0 ... 2559044.0 2743748.02018-01-07 4009104 3020789.0 ... 2350985.0 2441045.02018-01-08 4135505 2755266.0 ... 2523265.0 2622693.02018-01-09 4168506 2791601.0 ... 2727678.0 2627334.0[5 rows x 5 columns]['Shape of You', 'Despacito', 'Something Just Like This', 'HUMBLE.', 'Unforgettable']DatetimeIndex(['2017-01-06', '2017-01-07', '2017-01-08', '2017-01-09', '2017-01-10', '2017-01-11', '2017-01-12', '2017-01-13', '2017-01-14', '2017-01-15', ... '2017-12-31', '2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04', '2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08', '2018-01-09'], dtype='datetime64[ns]', name='Date', length=366, freq=None)
2. barplot 、heatmap 条形图、热图
2.1 barplot,条形图
# 柱状图、热图filepath = "flight_delays.csv"flight_data = pd.read_csv(filepath, index_col="Month")print(flight_data)plt.figure(figsize=(10, 6))plt.rcParams['font.sans-serif'] = 'SimHei' # 消除中文乱码plt.title("Spirit Airlines Flights月度晚点")sns.barplot(x=flight_data.index, y=flight_data['NK']) # x,y可以互换# 错误用法 x=flight_data['Month']plt.ylabel("到达晚点(分钟)")plt.show()
2.2 heatmap,热图
# 热图plt.figure(figsize=(14,7))plt.title("所有航班月度平均到达晚点(分钟)")sns.heatmap(data=flight_data,annot=True)# annot = True 每个单元格的值都显示在图表上# (不选择此项将删除每个单元格中的数字!)plt.xlabel("航班")plt.show()
3. scatterplot、regplot 散点图
3.1 scatterplot,普通散点图
# 散点图filepath = "insurance.csv"insurance_data = pd.read_csv(filepath)sns.scatterplot(x=insurance_data['bmi'], y=insurance_data['charges'])plt.show()
3.2 regplot,带回归线
# 带回归拟合线plotsns.regplot(x=insurance_data['bmi'], y=insurance_data['charges'])
3.3 scatterplot(x=,y=,hue=) ,hue带第三个变量区分
# 查看区分,是否吸烟 huesns.scatterplot(x=insurance_data['bmi'], y=insurance_data['charges'], hue=insurance_data['smoker'])
3.4 lmplot,3变量+2回归线
# 带两条回归线,展示3个变量的关系sns.lmplot(x='bmi',y='charges',hue='smoker',data=insurance_data)
3.5 swarmplot,分类散点图
# 分类散点图,不吸烟的花钱较少sns.swarmplot(x=insurance_data['smoker'],y=insurance_data['charges'])
下一篇:
转载地址:https://michael.blog.csdn.net/article/details/106128877 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年04月21日 18时30分37秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
基于SSM的兼职论坛系统的设计与实现
2021-07-03
基于java的ssm框架就业信息管理系统的设计
2021-07-03
Oracle字符串分隔符替换(替换奇数个或偶数个)
2021-07-03
Oracle 利用 UTL_SMTP 包发送邮件
2019-04-30
Oracle的pfile和spfile的一点理解和笔记
2019-04-30
2021-05-18
2019-04-30
基础架构系列篇-NGINX部署VUE
2019-04-30
基础架构系列篇-系统centos7安装kafka
2019-04-30
在 Vue 中用 Axios 异步请求API
2019-04-30
Mysql 之主从复制
2019-04-30
【NLP学习笔记】中文分词(Word Segmentation,WS)
2019-04-30
对于时间复杂度的通俗理解
2019-04-30
如何输入多组数据并输出每组数据的和?
2019-04-30
行阶梯型矩阵
2019-04-30
JAVA学习笔记6 - 数组
2019-04-30
【学习笔记】Android Activity
2019-04-30
location区段
2019-04-30
linux内存的寻址方式
2019-04-30
how2heap-double free
2019-04-30