http://blog.csdn.net/pipisorry/article/details/49515745
(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的优点:
安装pip install seaborn
Note: lz发现,就算你不用seaborn绘图,只要在matplotlib绘图中加上seaborn的import语句,就会以seaborn的图形方式展示图片,具有seaborn的效果。如:
import seaborn import matplotlib.pyplot as plt
注意要显示出图形,需要引入matplotlib并plt.show()出来。
皮皮blog
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
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. |
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)
数据有自己的结构。通常我们感兴趣的包含不同的组或类(这种情况下使用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参数提供列名,按我们的需要划分数据:
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. |
很整洁吧?随着你研究得越深,你可能想更细粒度地控制这些图表的细节。因为seaborn只是调用了matplotlib,那时你可能会想学习这个库。
from: http://blog.csdn.net/pipisorry/article/details/49515745ref: [seaborn API reference]*
[Seaborn tutorial]*
Python和数据科学的起步指南
Example gallery
Python数据可视化模块:Seaborn