[seaborn] seaborn学习笔记12-绘图实例(4) Drawing example(4)
文章目录
- 12 绘图实例(4) Drawing example(4)
- 1. Scatterplot with varying point sizes and hues(relplot)
- 2. Scatterplot with categorical variables(swarmplot)
- 3. Scatterplot Matrix(pairplot)
- 4. Scatterplot with continuous hues and sizes(scatterplot)
- 5. Violinplots with observations(violinplot)
- 6. Discovering structure in heatmap data(clustermap)
- 7. Lineplot from a wide-form dataset(lineplot)
- 8. Violinplot from a wide-form dataset(violinplot)
12 绘图实例(4) Drawing example(4)
(代码下载)
本文主要讲述seaborn官网相关函数绘图实例。具体内容有:
- Scatterplot with varying point sizes and hues(relplot)
- Scatterplot with categorical variables(swarmplot)
- Scatterplot Matrix(pairplot)
- Scatterplot with continuous hues and sizes(scatterplot)
- Violinplots with observations(violinplot)
- Discovering structure in heatmap data(clustermap)
- Lineplot from a wide-form dataset(lineplot)
- Violinplot from a wide-form dataset(violinplot)
# import packages
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
1. Scatterplot with varying point sizes and hues(relplot)
sns.set(style="white")
# Load the example mpg dataset
mpg = sns.load_dataset("mpg")
# Plot miles per gallon against horsepower with other semantics
# 其中x,y为横轴坐标变量,hue表示分类类别,size表示点的大小
sns.relplot(x="horsepower", y="mpg", hue="origin", size="weight",
sizes=(40, 400), alpha=.5, palette="muted",
height=6, data=mpg);
2. Scatterplot with categorical variables(swarmplot)
# Load the example iris dataset
iris = sns.load_dataset("iris")
# "Melt" the dataset to "long-form" or "tidy" representation
# 合并数据集
iris = pd.melt(iris, "species", var_name="measurement")
# Draw a categorical scatterplot to show each observation
# swarmplot将不同类别散点图用树状表示
sns.swarmplot(x="measurement", y="value", hue="species",
palette=["r", "c", "y"], data=iris);
3. Scatterplot Matrix(pairplot)
df = sns.load_dataset("iris")
#制作多变量图,hue为使用指定变量为分类变量画图
sns.pairplot(df, hue="species");
4. Scatterplot with continuous hues and sizes(scatterplot)
# Load the example iris dataset
planets = sns.load_dataset("planets")
# 设定颜色
#cubehelix_palette表示从cubehelix中制作顺序调色板
cmap = sns.cubehelix_palette(rot=-.2, as_cmap=True)
ax = sns.scatterplot(x="distance", y="orbital_period",
hue="year", size="mass",
palette=cmap, sizes=(10, 200),
data=planets)
5. Violinplots with observations(violinplot)
# Create a random dataset across several variables
rs = np.random.RandomState(0)
n, p = 40, 8
d = rs.normal(0, 2, (n, p))
d += np.log(np.arange(1, p + 1)) * -5 + 10
# Use cubehelix to get a custom sequential palette
pal = sns.cubehelix_palette(p, rot=-.5, dark=.3)
# Show each distribution with both violins and points
# 制作小提琴图,pal表示颜色
sns.violinplot(data=d, palette=pal, inner="points");
6. Discovering structure in heatmap data(clustermap)
# Load the brain networks example dataset
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
# Select a subset of the networks
used_networks = [1, 5, 6, 7, 8, 12, 13, 17]
used_columns = (df.columns.get_level_values("network")
.astype(int)
.isin(used_networks))
# 建立矩阵类数据集
df = df.loc[:, used_columns]
# Create a categorical palette to identify the networks
#创建调色盘
network_pal = sns.husl_palette(8, s=.45)
network_lut = dict(zip(map(str, used_networks), network_pal))
# Convert the palette to vectors that will be drawn on the side of the matrix
networks = df.columns.get_level_values("network")
network_colors = pd.Series(networks, index=df.columns).map(network_lut)
# Draw the full plot
# 将矩阵数据集绘制为分层聚类热图
# row_colors,col_color行或列标记的颜色列表
sns.clustermap(df.corr(), center=0, cmap="vlag",
row_colors=network_colors, col_colors=network_colors,
linewidths=.75, figsize=(13, 13));
7. Lineplot from a wide-form dataset(lineplot)
sns.set(style="whitegrid")
rs = np.random.RandomState(365)
values = rs.randn(365, 4).cumsum(axis=0)
dates = pd.date_range("1 1 2016", periods=365, freq="D")
data = pd.DataFrame(values, dates, columns=["A", "B", "C", "D"])
data = data.rolling(7).mean()
# 创建折线图
sns.lineplot(data=data, palette="tab10", linewidth=2.5);
8. Violinplot from a wide-form dataset(violinplot)
# Load the example dataset of brain network correlations
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
# Pull out a specific subset of networks
used_networks = [1, 3, 4, 5, 6, 7, 8, 11, 12, 13, 16, 17]
used_columns = (df.columns.get_level_values("network")
.astype(int)
.isin(used_networks))
#创建矩阵
df = df.loc[:, used_columns]
# Compute the correlation matrix and average over networks
# 计算相对系数和均值
corr_df = df.corr().groupby(level="network").mean()
corr_df.index = corr_df.index.astype(int)
corr_df = corr_df.sort_index().T
# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 6))
# Draw a violinplot with a narrower bandwidth than the default
sns.violinplot(data=corr_df, palette="Set3", bw=.2, cut=1, linewidth=1)
# Finalize the figure
ax.set(ylim=(-.7, 1.05))
sns.despine(left=True, bottom=True);
[seaborn] seaborn学习笔记12-绘图实例(4) Drawing example(4)的更多相关文章
- [seaborn] seaborn学习笔记11-绘图实例(3) Drawing example(3)
11 绘图实例(3) Drawing example(3)(代码下载) 本文主要讲述seaborn官网相关函数绘图实例.具体内容有: Plotting a diagonal correlation m ...
- [seaborn] seaborn学习笔记10-绘图实例(2) Drawing example(2)
文章目录 10 绘图实例(2) Drawing example(2) 1. Grouped violinplots with split violins(violinplot) 2. Annotate ...
- [seaborn] seaborn学习笔记9-绘图实例(1) Drawing example(1)
文章目录 9 绘图实例(1) Drawing example(1) 1. Anscombe's quartet(lmplot) 2. Color palette choices(barplot) 3. ...
- matlab学习笔记12单元数组和元胞数组 cell,celldisp,iscell,isa,deal,cellfun,num2cell,size
一起来学matlab-matlab学习笔记12 12_1 单元数组和元胞数组 cell array --cell,celldisp,iscell,isa,deal,cellfun,num2cell,s ...
- Spring源码学习笔记12——总结篇,IOC,Bean的生命周期,三大扩展点
Spring源码学习笔记12--总结篇,IOC,Bean的生命周期,三大扩展点 参考了Spring 官网文档 https://docs.spring.io/spring-framework/docs/ ...
- Ext.Net学习笔记12:Ext.Net GridPanel Filter用法
Ext.Net学习笔记12:Ext.Net GridPanel Filter用法 Ext.Net GridPanel的用法在上一篇中已经介绍过,这篇笔记讲介绍Filter的用法. Filter是用来过 ...
- SQL反模式学习笔记12 存储图片或其他多媒体大文件
目标:存储图片或其他多媒体大文件 反模式:图片存储在数据库外的文件系统中,数据库表中存储文件的对应的路径和名称. 缺点: 1.文件不支持Delete操作.使用SQL语句删除一条记录时,对应的文 ...
- golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题
golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题 今天测试了重新建一个项目生成新的表,然后复制到旧的项目 ...
- Spring MVC 学习笔记12 —— SpringMVC+Hibernate开发(1)依赖包搭建
Spring MVC 学习笔记12 -- SpringMVC+Hibernate开发(1)依赖包搭建 用Hibernate帮助建立SpringMVC与数据库之间的联系,通过配置DAO层,Service ...
随机推荐
- html点击a标签弹窗QQ聊天界面
以为很难.以为要第三方.谁知道不用.一句话的事情. 1 <a hfer="tencent://message/?uin=12345&Site=&Menu-=yes&qu ...
- JavaScript中的代码执行顺序
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head&g ...
- go-zero docker-compose 搭建课件服务(二):编写courseware rpc服务
0.转载 go-zero docker-compose 搭建课件服务(二):编写courseware rpc服务 0.1源码地址 https://github.com/liuyuede123/go-z ...
- markdown第一天学习
Markdown学习 标题: 空格+标题名字后回车 二级标题 空格+标题名字后回车 三级标题 空格+标题名字后回车 四级标题 空格+标题名字后回车 字体 粗体 hello,world!------两边 ...
- JUC中的AQS底层详细超详解
摘要:当你使用java实现一个线程同步的对象时,一定会包含一个问题:你该如何保证多个线程访问该对象时,正确地进行阻塞等待,正确地被唤醒? 本文分享自华为云社区<JUC中的AQS底层详细超详解,剖 ...
- 使用 nvm 对 node 进行版本管理
前端项目工程化,基本都依赖于 nodejs, 不同的项目对于 nodejs 的版本会有要求,nvm 就是可以让我们在各个版本之间进行快速切换的工具. Linux 系统 下载解压 查看所有版本 , 选择 ...
- centos7离线安装PHP7
环境 centos7.9 PHP7.4.30 准备工作 在编译PHP时会提示一些包版本不够或者缺少某些包,一般选择yum来安装缺少的包,但因为是离线安装,所以可以手动配置本地yum源.先看一下系统版本 ...
- webpack优化项目
在使用vue 构建项目的时候 ,会用到vue.js, vue-router.js, 等库,通常打包的话会将这些公用的代码打包的一个文件中,导致该文件过大影响加载的速度.那么可以考虑使用cdn 加速的方 ...
- Go语言核心36讲16----接口
你好,我是郝林,今天我们来聊聊接口的相关内容. 前导内容:正确使用接口的基础知识 在Go语言的语境中,当我们在谈论"接口"的时候,一定指的是接口类型.因为接口类型与其他数据类型不同 ...
- cmd唤醒windows设置,并配置opsshd
1. 从cmd唤起windows设置 这个东西很有意思,大部分在运行窗口输入的内容,从cmd或powershell都能唤起,如:control控制面板,但偶尔有些操作就不能通用, 如: ms-sett ...