矩阵图

https://datawhalechina.github.io/pms50/#/chapter9/chapter9

导入所需要的库

import numpy as np              # 导入numpy库
import pandas as pd # 导入pandas库
import matplotlib as mpl # 导入matplotlib库
import matplotlib.pyplot as plt
import seaborn as sns # 导入seaborn库
%matplotlib inline # 在jupyter notebook显示图像

设定图像各种属性

large = 22; med = 16; small = 12

params = {'axes.titlesize': large,    # 设置子图上的标题字体
'legend.fontsize': med, # 设置图例的字体
'figure.figsize': (16, 10), # 设置图像的画布
'axes.labelsize': med, # 设置标签的字体
'xtick.labelsize': med, # 设置x轴上的标尺的字体
'ytick.labelsize': med, # 设置整个画布的标题字体
'figure.titlesize': large}
#plt.rcParams.update(params) # 更新默认属性
plt.style.use('seaborn-whitegrid') # 设定整体风格
sns.set_style("white") # 设定整体背景风格

程序代码

# step1:导入数据

df = sns.load_dataset('iris')

# step2: 绘制矩阵图

    # 画布
plt.figure(figsize = (12, 10), # 画布尺寸_(12, 10)
dpi = 80) # 分辨率_80
# 矩阵图
sns.pairplot(df, # 使用的数据
kind = 'scatter', # 绘制图像的类型_scatter
hue = 'species', # 类别的列,让不同类别具有不谈的颜色
plot_kws = dict(s = 50, # 点的尺寸
edgecolor = 'white', # 边缘颜色
linewidth = 2.5)) # 线宽

# step1:导入数据

df = sns.load_dataset('iris')

# step2: 绘制矩阵图

    # 画布
plt.figure(figsize = (12, 10), # 画布尺寸_(12, 10)
dpi = 80) # 分辨率_80
# 矩阵图(带有拟合线的散点图)
sns.pairplot(df, # 使用的数据
kind = 'reg', # 绘制图像的类型_reg
hue = 'species') # 类别的列,让不同类别具有不谈的颜色

博文总结

seaborn.pairplot

seaborn.pairplot(data, hue=None, hue_order=None,
palette=None, vars=None, x_vars=None, y_vars=None, kind='scatter',
diag_kind='auto', markers=None, height=2.5, aspect=1,
dropna=True, plot_kws=None, diag_kws=None, grid_kws=None, size=None)

Plot pairwise relationships in a dataset.

By default, this function will create a grid of Axes such that each variable in data will by shared in the y-axis across a single row and in the x-axis across a single column.

The diagonal Axes are treated differently, drawing a plot to show the univariate distribution of the data for the variable in that column.

It is also possible to show a subset of variables or plot different variables on the rows and columns.

This is a high-level interface for PairGrid that is intended to make it easy to draw a few common styles. You should use PairGriddirectly if you need more flexibility.

参数:data:DataFrame

Tidy (long-form) dataframe where each column is a variable and each row is an observation.

hue:string (variable name), optional

Variable in data to map plot aspects to different colors.

hue_order:list of strings

Order for the levels of the hue variable in the palette

palette:dict or seaborn color palette

Set of colors for mapping the hue variable. If a dict, keys should be values in the hue variable.

vars:list of variable names, optional

Variables within data to use, otherwise use every column with a numeric datatype.

{x, y}_vars:lists of variable names, optional

Variables within data to use separately for the rows and columns of the figure; i.e. to make a non-square plot.

kind:{‘scatter’, ‘reg’}, optional

Kind of plot for the non-identity relationships.

diag_kind:{‘auto’, ‘hist’, ‘kde’}, optional

Kind of plot for the diagonal subplots. The default depends on whether "hue" is used or not.

markers:single matplotlib marker code or list, optional

Either the marker to use for all datapoints or a list of markers with a length the same as the number of levels in the hue variable so that differently colored points will also have different scatterplot markers.

height:scalar, optional

Height (in inches) of each facet.

aspect:scalar, optional

Aspect * height gives the width (in inches) of each facet.

dropna:boolean, optional

Drop missing values from the data before plotting.

{plot, diag, grid}_kws:dicts, optional

Dictionaries of keyword arguments.

返回值:grid:PairGrid

Returns the underlying PairGrid instance for further tweaking.

seaborn.load_dataset

seaborn.load_dataset(name, cache=True, data_home=None, **kws)

从在线库中获取数据集(需要联网)。

参数:name:字符串

数据集的名字 (<cite>name</cite>.csv on https://github.com/mwaskom/seaborn-data)。 您可以通过 get_dataset_names() 获取可用的数据集。

cache:boolean, 可选

如果为True,则在本地缓存数据并在后续调用中使用缓存。

data_home:string, 可选

用于存储缓存数据的目录。 默认情况下使用 ~/seaborn-data/

kws:dict, 可选

传递给 pandas.read_csv

数据可视化实例(十一): 矩阵图(matplotlib,pandas)的更多相关文章

  1. 【Matplotlib】数据可视化实例分析

    数据可视化实例分析 作者:白宁超 2017年7月19日09:09:07 摘要:数据可视化主要旨在借助于图形化手段,清晰有效地传达与沟通信息.但是,这并不就意味着数据可视化就一定因为要实现其功能用途而令 ...

  2. 数据可视化实例(十四):面积图 (matplotlib,pandas)

    偏差 (Deviation) 面积图 (Area Chart) 通过对轴和线之间的区域进行着色,面积图不仅强调峰和谷,而且还强调高点和低点的持续时间. 高点持续时间越长,线下面积越大. https:/ ...

  3. 数据可视化实例(三): 散点图(pandas,matplotlib,numpy)

    关联 (Correlation) 关联图表用于可视化2个或更多变量之间的关系. 也就是说,一个变量如何相对于另一个变化. 散点图(Scatter plot) 散点图是用于研究两个变量之间关系的经典的和 ...

  4. seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化

    一.线性关系数据可视化lmplot( ) 表示对所统计的数据做散点图,并拟合一个一元线性回归关系. lmplot(x, y, data, hue=None, col=None, row=None, p ...

  5. seaborn分布数据可视化:直方图|密度图|散点图

    系统自带的数据表格(存放在github上https://github.com/mwaskom/seaborn-data),使用时通过sns.load_dataset('表名称')即可,结果为一个Dat ...

  6. 数据可视化实例(十四):带标记的发散型棒棒糖图 (matplotlib,pandas)

    偏差 (Deviation) 带标记的发散型棒棒糖图 (Diverging Lollipop Chart with Markers) 带标记的棒棒糖图通过强调您想要引起注意的任何重要数据点并在图表中适 ...

  7. 数据可视化实例(十七):包点图 (matplotlib,pandas)

    排序 (Ranking) 包点图 (Dot Plot) 包点图表传达了项目的排名顺序,并且由于它沿水平轴对齐,因此您可以更容易地看到点彼此之间的距离. https://datawhalechina.g ...

  8. 数据可视化实例(九): 边缘箱形图(matplotlib,pandas)

    https://datawhalechina.github.io/pms50/#/chapter7/chapter7 边缘箱形图 (Marginal Boxplot) 边缘箱图与边缘直方图具有相似的用 ...

  9. 数据可视化实例(七): 计数图(matplotlib,pandas)

    https://datawhalechina.github.io/pms50/#/chapter5/chapter5 计数图 (Counts Plot) 避免点重叠问题的另一个选择是增加点的大小,这取 ...

随机推荐

  1. 在MS SQL(SSMS中)_Format_SQL_更改设置_增加命令

    在MS SQL(SSMS中)_Format_SQL_更改设置_增加命令 目的:要格式化这么一段SQL语句(这是随便从网上Copy的一段),没细看内容,反正看到头疼,乱七八糟的不想看. select b ...

  2. Java 多线程基础(六)线程等待与唤醒

    Java 多线程基础(六)线程等待与唤醒 遇到这样一个场景,当某线程里面的逻辑需要等待异步处理结果返回后才能继续执行.或者说想要把一个异步的操作封装成一个同步的过程.这里就用到了线程等待唤醒机制. 一 ...

  3. Ehcache基础入门

    1. 基本介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认CacheProvider.Ehcache是一种广泛使用的开源Java分布式缓存.主要 ...

  4. 爬取B站弹幕并且制作词云

    目录 爬取弹幕 1. 从手机端口进入网页爬取找到接口 2.代码 制作词云 1.文件读取 2.代码 爬取弹幕 1. 从手机端口进入网页爬取找到接口 2.代码 import requests from l ...

  5. Perl入门(四)Perl的正则表达式

    正则表达式是Perl语言的特色,基本的语法不是很难,但是编写一个符合需求.高效的正则表达式,还是有一些挑战的. Perl的三种匹配模式 1.查找 语法:m/正则表达式内容/; 作用:查找匹配内容中是否 ...

  6. apply()方法和call()介绍

    我们发现apply()和call()的真正用武之地是能够扩充函数赖以运行的作用域. 1.call,apply都属于Function.prototype的一个方法,它是JavaScript引擎内在实现的 ...

  7. JavaScript基础对象创建模式之对象的常量(028)

    虽然许多编程语言提供了const关键字来支持常量的声明,但JavaScript里没有表示常量的语义.我们可以用全大写的方式来声明变量,表明它实际上是个常量: Math.PI; // 3.1415926 ...

  8. Nginx 从入门到放弃(四)

    前面我们学习了nginx的基本操作和日志管理,今天我们学习一下生产环境经常会用到的路由定位location设置,在工作中,经常可能会出现怎么设置的路由访问不到网页呀?总是出现404错误啊,这些都很有可 ...

  9. JavaScript常用API合集汇总(一)

    今天这篇文章跟大家分享一些JavaScript常用的API代码,有DOM操作.CSS操作.对象(Object对象.Array对象.Number对象.String对象.Math对象.JSON对象和Con ...

  10. CentOS/RHEL 6.4/5.9 安装 Adobe Flash Player 11.2

    1.root登录: $ su 2.安装 Adobe YUM Repository RPM package X86_64 ________________________________________ ...