在本节学习中,我们使用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数据可视化入门的更多相关文章

  1. 数据可视化入门之show me the numbers

           数据的可视化一直是自己瞎玩着学,近来想系统的学数据可视化的东西,于是搜索资料时看到有人推荐<show me the numbers>作为入门. 由于搜不到具体的书籍内容,只能 ...

  2. seaborn 数据可视化(一)连续型变量可视化

    一.综述 Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,图像也更加美观,本文基于seaborn官方API还有自己的一些理解.   1.1.样式控制: ...

  3. python学习笔记(2):科学计算及数据可视化入门

    一.NumPy 1.NumPy:Numberical Python 2.高性能科学计算和数据分析的基础包 3.ndarray,多维数组(矩阵),具有矢量运算的能力,快速.节省空间 (1)ndarray ...

  4. seaborn 数据可视化(二)带有类别属性的数据可视化

    Seaborn的分类图分为三类,将分类变量每个级别的每个观察结果显示出来,显示每个观察分布的抽象表示,以及应用统计估计显示的权重趋势和置信区间: 第一个包括函数swarmplot()和stripplo ...

  5. PoPo数据可视化周刊第4期

    PoPo数据可视化 聚焦于Web数据可视化与可视化交互领域,发现可视化领域有意思的内容.不想错过可视化领域的精彩内容, 就快快关注我们吧 :) 微信号:popodv_com   由于国庆节的原因,累计 ...

  6. Python数据可视化-seaborn库之countplot

    在Python数据可视化中,seaborn较好的提供了图形的一些可视化功效. seaborn官方文档见链接:http://seaborn.pydata.org/api.html countplot是s ...

  7. kaggle入门项目:Titanic存亡预测(三)数据可视化与统计分析

    ---恢复内容开始--- 原kaggle比赛地址:https://www.kaggle.com/c/titanic 原kernel地址:A Data Science Framework: To Ach ...

  8. 数据可视化 seaborn绘图(1)

    seaborn是基于matplotlib的数据可视化库.提供更高层的抽象接口.绘图效果也更好. 用seaborn探索数据分布 绘制单变量分布 绘制二变量分布 成对的数据关系可视化 绘制单变量分布 se ...

  9. Python图表数据可视化Seaborn:3. 线性关系数据| 时间线图表| 热图

    1. 线性关系数据可视化 lmplot( ) import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...

随机推荐

  1. 对vue中nextTick()的理解及使用场景说明

    异步更新队列: 首先我们要对vue的数据更新有一定理解: vue是依靠数据驱动视图更新的,该更新的过程是异步的. 即:当侦听到你的数据发生变化时, Vue将开启一个队列(该队列被Vue官方称为异步更新 ...

  2. Java学习多线程第二天

    内容介绍 线程安全 线程同步 死锁 Lock锁 等待唤醒机制 1    多线程 1.1     线程安全 如果有多个线程在同时运行,而这些线程可能会同时运行这段代码.程序每次运行结果和单线程运行的结果 ...

  3. requestAnimationFrame 兼容方案

    [toc] 编写涉及:css, html, js 在线演示codepen html代码 <div class="roll-box"> <div class=&qu ...

  4. 在canvas中使用其他HTML元素

    做一个功能如下图,随机生成100个大小.颜色随机的小球.点击开始运动的时候,小球开始运动,然后点击停止运动的时候,小球停止运动. 点击旁边的白色或者黑色,则背景颜色变为相应的颜色. HTML部分: & ...

  5. Source Maps简介

    提高网站性能最简单的方式之一是合并压缩JavaScript和CSS文件.但是当你需要调试这些压缩文件中的代码时,那将会是一场噩梦.不过也不用担心,souce maps将会帮你解决这一问题. Sourc ...

  6. Rootkit与后门隐藏技术

    目录 简介 linux虚拟文件系统VFS rootkit的功能 隐藏文件 基本方法 高级方法 系统调用流程 hook sys_getdents sys_getdents的调用树 最底层的方法 隐藏进程 ...

  7. git 常规业务场景 使用

    一般每个开发者都会有个自己的分支,有个test分支,合并代码用,两条分支相互备份,就算merge的时候被覆盖,也不用担心 建立自己的分支 // 创建本地分支, git checkout -b dev_ ...

  8. 第一章 .NET基础-C#基础

    一.1.1. 基础语法 一.1.1.1. 注释符 一.1.1.1.1. 注释符的作用 l 注释 l 解释 一.1.1.1.2. C#中的3中注释符 l 单行注释 // l 多上注释 /* 要注释的内容 ...

  9. 基于HttpClient4.5.1实现Http访问工具类

    本工具类基于httpclient4.5.1实现 <dependency> <groupId>org.apache.httpcomponents</groupId> ...

  10. springbootl用thymeleaf整合htm

    pom文件: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...