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 ...
随机推荐
- ALS音乐推荐(上)
本篇文章的开头笔者提出一个疑问,何为数据科学,数据科学是做什么的?大家带着这个疑问去读接下来的这篇音乐推荐的公众号. 从经验上讲,推荐引擎属于大规模机器学习,在日常购物中大家或许深有体会,比如:你在淘 ...
- laypage分页控件使用方法
laypage是一款非常简单易用的分页控件,由于最近项目中使用到了,简单记录一下使用方法 1.引入laypage所需的js和css文件 <link href="js/laypage/1 ...
- VINS 估计器之检查视差
为什么检查视差 VINS里为了控制优化计算量,在实时情况下,只对当前帧之前某一部分帧进行优化,而不是全部历史帧.局部优化帧的数量就是窗口大小.为了维持窗口大小,需要去除旧的帧添加新的帧,也就是边缘化 ...
- [LeetCode] 01 Matrix 零一矩阵
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance b ...
- Docker入门之--基础知识
1.先是在Mac上安装. 按照这两个就可以很简单的完成 https://docs.docker.com/docker-for-mac/ https://docs.docker.com/docker-f ...
- [HNOI 2013]游走
Description 题库链接 一个无向连通图,顶点从 \(1\) 编号到 \(N\) ,边从 \(1\) 编号到 \(M\) . 小Z在该图上进行随机游走,初始时小Z在 \(1\) 号顶点,每一步 ...
- [HNOI 2011]数学作业
Description 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 N 和 M,要求计算 Concatenate (1 .. N) Mod M 的值,其中 Con ...
- [TJOI2017]异或和
题目描述 在加里敦中学的小明最近爱上了数学竞赛,很多数学竞赛的题都是与序列的连续和相关的.所以对于一个序列,求出它们所有的连续和来说,小明觉得十分的 简单.但今天小明遇到了一个序列和的难题,这个题目不 ...
- 洛谷P1446 [HNOI2008]Cards
置换群+dp #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring& ...
- 【BZOJ1040】【ZJOI2008】骑士
Description Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战 ...