Seaborn数据可视化入门
在本节学习中,我们使用Seaborn作为数据可视化的入门工具
Seaborn的官方网址如下:http://seaborn.pydata.org
一:definition
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.
Seaborn是基于matplotlib的数据可视化库,它的主要功能是做数据可视化
二:Setup the notebook
对数据进行初始化,引入相应的包
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
pirnt("Setup Complete")
三: Load the data
加载数据
file_path = "../input/fifa.csv"
fifa_data = pd.read_csv(file_path, index_col="Date", parse_Dates=True)
注:
file_path:
表示dataset的路径
idnex_col="Date" :
When we load the dataset, we want each entry in the first column to denote a different row. To do this, we set the value of index_col
to the name of the first column ("Date"
, found in cell A1 of the file when it's opened in Excel).
parse_dates=True:
This tells the notebook to understand the each row label as a date (as opposed to a number or other text with a different meaning).
四: Examine the data
列出数据的前5行检验:
fifa_data.head()
五: Plot the data
- Line Chart
plt.figure(figsize=(16,6))
sns.lineplot(data=fifa_data)
注:
plt.figure(figsize=(16,6))
设定的是图形的宽度和高度
plt.title("name") 增加title,并命名为name
sns.lineplot(data=fifa_data)画出数据的线状图
若想plot a subset of the data (仅仅画出一部分图线):
sns.lineplot(data=spotify["shape of you"],label=shape of you")
sns.lineplot(data=spotify["despacito"], label="despatito")
plt.xlabel("name X")
plt.blabel("name Y")
注:
plt.xlabel
plt.ylabel
是分别对label x, y 进行命名
- Bar Charts
plt.title("Average Arrival Delay for Spirit Airlines Flights, by Month")
sns.barplot(x=flight_data.index, y=flight_data['NK'])
plt.ylabel("Arrival delay (in minutes)"
注:
x=flight_data.index :
This determines what to use on the horizontal axis. In this case, we have selected the column that indexes the rows (in this case, the column containing the months).
- Heat Maps
plt.figure(figsize=(16,6))
plt.title("Average Arrival Delay for Each Airline, by Month")
sns.heatmap(data=flight_data,annot=True)
plt.xlabel("Airline")
注:
sns.heatmap:
This tells the notebook that we want to create a heatmap.
data=flight_data:
This tells the notebook to use all of the entries in flight_data to create the heatmap
annot=Ture:
This ensures that the vlaues for each cell appear on the chart.
- Scatter plots
(1) sns.scatterplot (x=insurance_data['bmi'], y=insurance_data['charges'])
注:
the horizontal x-axis (x=insurance_data['bmi']
)
the vertical y-axis (y=insurance_data['charges']
)
(2) 为了看出点的关系强度,可以使用regression line(回归线)
sns.regplot(x=insurance_data['bmi'], y=insurance_data['charges'])
(3) sns.scatterplot(x=insurance_data['bmi'], y=insurance_data['charges'], hue=insurance_data['smoker'])
hue=insurance_data['smoker']:按照hue来对数据进行标色
- Histograms
sns.distplot(a=iris_data['Petal Length (cm)'], kde=False)
- Density plots
更平滑的图:
sns.kdeplot(data=iris_data['Petal Length(cm)'], shade=True)
六:Conclusion
下图显示,在seaborn中,选择图形需要根据需求来决定
Seaborn数据可视化入门的更多相关文章
- 数据可视化入门之show me the numbers
数据的可视化一直是自己瞎玩着学,近来想系统的学数据可视化的东西,于是搜索资料时看到有人推荐<show me the numbers>作为入门. 由于搜不到具体的书籍内容,只能 ...
- seaborn 数据可视化(一)连续型变量可视化
一.综述 Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,图像也更加美观,本文基于seaborn官方API还有自己的一些理解. 1.1.样式控制: ...
- python学习笔记(2):科学计算及数据可视化入门
一.NumPy 1.NumPy:Numberical Python 2.高性能科学计算和数据分析的基础包 3.ndarray,多维数组(矩阵),具有矢量运算的能力,快速.节省空间 (1)ndarray ...
- seaborn 数据可视化(二)带有类别属性的数据可视化
Seaborn的分类图分为三类,将分类变量每个级别的每个观察结果显示出来,显示每个观察分布的抽象表示,以及应用统计估计显示的权重趋势和置信区间: 第一个包括函数swarmplot()和stripplo ...
- PoPo数据可视化周刊第4期
PoPo数据可视化 聚焦于Web数据可视化与可视化交互领域,发现可视化领域有意思的内容.不想错过可视化领域的精彩内容, 就快快关注我们吧 :) 微信号:popodv_com 由于国庆节的原因,累计 ...
- Python数据可视化-seaborn库之countplot
在Python数据可视化中,seaborn较好的提供了图形的一些可视化功效. seaborn官方文档见链接:http://seaborn.pydata.org/api.html countplot是s ...
- kaggle入门项目:Titanic存亡预测(三)数据可视化与统计分析
---恢复内容开始--- 原kaggle比赛地址:https://www.kaggle.com/c/titanic 原kernel地址:A Data Science Framework: To Ach ...
- 数据可视化 seaborn绘图(1)
seaborn是基于matplotlib的数据可视化库.提供更高层的抽象接口.绘图效果也更好. 用seaborn探索数据分布 绘制单变量分布 绘制二变量分布 成对的数据关系可视化 绘制单变量分布 se ...
- Python图表数据可视化Seaborn:3. 线性关系数据| 时间线图表| 热图
1. 线性关系数据可视化 lmplot( ) import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...
随机推荐
- 聊聊目标管理之 OKR
这篇文章我们不谈技术,聊点轻松的,那聊什么呢?聊一下最近很火的目标管理 OKR.不知道小伙伴你们的公司什么情况,我的公司今年开始推行 OKR,用了大半年的时间,感觉效果还不错,上周六又参加了一天的复盘 ...
- HTML/CSS:图片居中(水平居中和垂直居中)
css图片居中(水平居中和垂直居中) css图片居中分css图片水平居中和垂直居中两种情况,有时候还需要图片同时水平垂直居中, 下面分几种居中情况分别介绍: css图片水平居中 1.利用margin: ...
- 原生JavaScript(js)手把手教你写轮播图插件(banner)
---恢复内容开始--- 1.轮播图插件 1.什么是插件: 为已有的程序增加功能 2.插件的特点(为什么要做成一个插件)与注意事项: 1.通用性,可移植性强 2.兼容性:不会对其他代码产生影响 3.创 ...
- 关于修改主机名和ssh免密登录
修改主机名的常规方法: 1.hostname name2.echo name > /proc/sys/kernel/hostname3.sysctl kernel.hostname=name4 ...
- Python 面向導向語言 Object Oriented Programming Language
Pytho 是面向對象的程式語言,舉凡 Literals 值都是 Object.例如: >>> id(38)8791423739696 與 >>> id('ABC' ...
- 项目启动会(project initiating meeting)与项目开工会(kick-off meeting)区别
一.项目启动会initiating meeting 召开时间:是启动阶段结束时召开的会议:主要任务:发布项目章程,并任命项目经理,赋予项目经理动用组织资源的权力:注意事项:(1)会议召开前已经对干系人 ...
- Swoole引擎原理的快速入门干货
更多内容,欢迎关注微信公众号:全菜工程师小辉~ 过去一年使用PHP和Java两种技术栈完成了一个游戏服务器项目.由于项目中有高频的网络请求,所以PHP技术栈尝试使用Swoole引擎(基于事件的高性能异 ...
- Spring MVC内置支持的4种内容协商方式【享学Spring MVC】
每篇一句 十个光头九个富,最后一个会砍树 前言 不知你在使用Spring Boot时是否对这样一个现象"诧异"过:同一个接口(同一个URL)在接口报错情况下,若你用rest访问,它 ...
- silverlight中递归构造无限级树treeview+checkbox
两个实体,其实一个实体也能构造出来,我这里是为了增加一个 checkbox //第一个实体 public class person { public int no { get; set; } publ ...
- .Net之微信小程序获取用户UnionID
前言: 在实际项目开发中我们经常会遇到账号统一的问题,如何在不同端或者是不同的登录方式下保证同一个会员或者用户账号唯一(便于用户信息的管理).这段时间就有一个这样的需求,之前有个客户做了一个微信小程序 ...