Matplotlib Toolkits:python高级绘图库seaborn
http://blog.csdn.net/pipisorry/article/details/49515745
Seaborn介绍
seaborn
(Not distributed with matplotlib)
seaborn is a highlevel interface for drawing statistical graphics with matplotlib. Itaims to make visualization a central part of exploring andunderstanding complex datasets.
[seaborn¶]
Matplotlib是Python主要的绘图库。但是不建议你直接使用它,原因与不推荐你使用NumPy是一样的。虽然Matplotlib很强大,它本身就很复杂,你的图经过大量的调整才能变精致。因此,作为替代推荐一开始使用Seaborn。
Seaborn本质上使用Matplotlib作为核心库(就像Pandas对NumPy一样)。
seaborn的优点:
- 默认情况下就能创建赏心悦目的图表。(只有一点,默认不是jet colormap)
- 创建具有统计意义的图
- 能理解pandas的DataFrame类型,所以它们一起可以很好地工作。
安装pip install seaborn
Note: lz发现,就算你不用seaborn绘图,只要在matplotlib绘图中加上seaborn的import语句,就会以seaborn的图形方式展示图片,具有seaborn的效果。如:
import seaborn import matplotlib.pyplot as plt
注意要显示出图形,需要引入matplotlib并plt.show()出来。
Seaborn使用
Style functions: API | Tutorial
Color palettes: API | Tutorial
Distribution plots: API | Tutorial
Regression plots: API | Tutorial
Categorical plots: API | Tutorial
Axis grid objects: API | Tutorial
分布图绘制Distribution plots
jointplot(x, y[, data, kind, stat_func, ...]) |
Draw a plot of two variables with bivariate and univariate graphs. |
pairplot(data[, hue, hue_order, palette, ...]) |
Plot pairwise relationships in a dataset. |
distplot(a[, bins, hist, kde, rug, fit, ...]) |
Flexibly plot a univariate distribution of observations. |
kdeplot(data[, data2, shade, vertical, ...]) |
Fit and plot a univariate or bivariate kernel density estimate. |
rugplot(a[, height, axis, ax]) |
Plot datapoints in an array as sticks on an axis. |
单变量绘制distplot
seaborn.distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None, hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, color=None, vertical=False, norm_hist=False, axlabel=None, label=None, ax=None)
Note:
1 如果想显示统计个数而不是概率,需要同时设置norm_hist=False, kde=False。
2 自己指定fit的函数from scipy import stats ... fit=stats.norm
>>> import seaborn as sns, numpy as np
>>> sns.set(rc={"figure.figsize": (8, 4)}); np.random.seed(0)
>>> x = np.random.randn(100)
>>> ax = sns.distplot(x)
双变量+单变量统一绘制jointplot
使用matplotlib重新绘制这幅图的话需要相当多的(丑陋)代码,包括调用scipy执行线性回归并手动利用线性回归方程绘制直线(我甚至想不出怎么在边界绘图,怎么计算置信区间)。
[the tutorial on quantitative linear models]
与Pandas的DataFrame很好地工作
数据有自己的结构。通常我们感兴趣的包含不同的组或类(这种情况下使用pandas中groupby的功能会让人感到很神奇)。比如tips(小费)的数据集是这样的:
Out[9]:
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
我们可能想知道吸烟者给的小费是否与不吸烟的人不同。没有seaborn的话,这需要使用pandas的groupby功能,并通过复杂的代码绘制线性回归直线。使用seaborn的话,我们可以给col参数提供列名,按我们的需要划分数据:
回归图绘制Regression plots
lmplot(x, y, data[, hue, col, row, palette, ...]) |
Plot data and regression model fits across a FacetGrid. |
regplot(x, y[, data, x_estimator, x_bins, ...]) |
Plot data and a linear regression model fit. |
residplot(x, y[, data, lowess, x_partial, ...]) |
Plot the residuals of a linear regression. |
interactplot(x1, x2, y[, data, filled, ...]) |
Visualize a continuous two-way interaction with a contour plot. |
coefplot(formula, data[, groupby, ...]) |
Plot the coefficients from a linear model. |
sns.lmplot("total_bill","tip",tips,col="smoker");

很整洁吧?随着你研究得越深,你可能想更细粒度地控制这些图表的细节。因为seaborn只是调用了matplotlib,那时你可能会想学习这个库。
from:http://blog.csdn.net/pipisorry/article/details/49515745
ref: [seaborn API reference]*
Matplotlib Toolkits:python高级绘图库seaborn的更多相关文章
- matplotlib python高级绘图库 一周总结
matplotlib python高级绘图库 一周总结 官网 http://matplotlib.org/ 是一个python科学作图库,可以快速的生成很多非常专业的图表. 只要你掌握要领,画图将变得 ...
- Python中用绘图库绘制一条蟒蛇
一..构思设计蟒蛇的长度颜色等 首先,我们来构思一个简单的蟒蛇.让它的颜色为黄色,形状为一条正在爬行的蟒蛇. 二..准备绘图库 Python中有一个绘图库叫turtle我们先引入它. import t ...
- 23、matplotlib数据可视化、绘图库模块
matplotlib官方文档:https://matplotlib.org/contents.html?v=20190307135750 matplotlib是一个绘图库,它可以创建常用的统计图,包括 ...
- Python第三方库matplotlib(2D绘图库)入门与进阶
Matplotlib 一 简介: 二 相关文档: 三 入门与进阶案例 1- 简单图形绘制 2- figure的简单使用 3- 设置坐标轴 4- 设置legend图例 5- 添加注解和绘制点以及在图形上 ...
- Python图表绘制:matplotlib绘图库入门
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- Python图表绘制:matplotlib绘图库入门(转)
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- Python Matplotlib绘图库 安装
一般我们在做科学计算的时候,首先会想到的是matlab,但是呢,一想到matlab安装包那么大,我就有点不想说什么了. Matplotlib 是python最著名的绘图库,它提供了一整套和matlab ...
- 使用 Python 的 matplotlib 绘图库进行绘图
matplotlib 是 Python 最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 1 使用 Ma ...
- python 绘图库 Matplotlib
matplotlib官方文档 使用Matplotlib,能够轻易生成各种图像,例如:直方图.波谱图.条形图.散点图等. 入门代码实例 import matplotlib.pyplot as plt i ...
随机推荐
- Linux下的MySQL5.7.14启动方法
启动MySQL服务: systemctl start mysql 启动MySQL服务(安全方式): mysqld_safe --user=mysql & 登录MySQL(有密码): mysql ...
- UEditor Golang上传图片与附件
UEditor图片与附件上传官方只支持ASP.ASP.NET.JSP.PHP四种语言版本,Golang就不在其中.因为自己开发系统的需要,我照着UEditor服务器端的接口自己实现了一个Golang版 ...
- 原生Js操作DOM
查找DOM .querySelectorAll(),它接受包含一个CSS选择器的字符串参数,返回一个表示文档中匹配选择器的所有元素的NodeList元素. .querySelector(),返回第一个 ...
- bzoj4919 [Lydsy1706月赛]大根堆
Description 给定一棵n个节点的有根树,编号依次为1到n,其中1号点为根节点.每个点有一个权值v_i. 你需要将这棵树转化成一个大根堆.确切地说,你需要选择尽可能多的节点,满足大根堆的性质: ...
- bzoj 4919: [Lydsy六月月赛]大根堆
Description 给定一棵n个节点的有根树,编号依次为1到n,其中1号点为根节点.每个点有一个权值v_i. 你需要将这棵树转化成一个大根堆.确切地说,你需要选择尽可能多的节点,满足大根堆的性质: ...
- ●POJ 1195 Mobile phones
题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...
- hdu 5919 主席树(区间不同数的个数 + 区间第k大)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- [bzoj4828][Ah/Hnoi2017]大佬
来自FallDream的博客,未经允许,请勿转载,谢谢. 人们总是难免会碰到大佬.他们趾高气昂地谈论凡人不能理解的算法和数据结构,走到任何一个地方,大佬的气场就能让周围的人吓得瑟瑟发抖,不敢言语. 你 ...
- PTA 字符串关键字的散列映射(25 分)
7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...
- 分布式改造剧集之Redis缓存采坑记
Redis缓存采坑记 前言 这个其实应该属于分布式改造剧集中的一集(第一集见前面博客:http://www.cnblogs.com/Kidezyq/p/8748961.html),本来按照顺序 ...