Python数据扩展包之Seaborn

官方API:http://seaborn.pydata.org/index.html

案例库:http://seaborn.pydata.org/examples/index.html

学习资料:https://www.datacamp.com/community/tutorials/seaborn-python-tutorial

可视化:Python数据可视化-seaborn

简介

Seaborn是一种基于matplotlib的图形可视化python libraty。它提供了一种高度交互式界面,便于用户能够做出各种有吸引力的统计图表。

Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,在大多数情况下使用seaborn就能做出很具有吸引力的图,而使用matplotlib就能制作具有更多特色的图。应该把Seaborn视为matplotlib的补充,而不是替代物。同时它能高度兼容numpypandas数据结构以及scipystatsmodels等统计模式。掌握seaborn能很大程度帮助我们更高效的观察数据与图表,并且更加深入了解它们。

Python数据扩展包之Seaborn_第1张图片

特点:

  • 基于matplotlib aesthetics绘图风格,增加了一些绘图模式
  • 增加调色板功能,利用色彩丰富的图像揭示您数据中的模式
  • 运用数据子集绘制与比较单变量和双变量分布的功能
  • 运用聚类算法可视化矩阵数据
  • 灵活运用处理时间序列数据
  • 利用网格建立复杂图像集

安装seaborn

  • 利用pip安装
pip install seaborn
  • Anaconda环境下
conda install seaborn

函数

  • set_style( )是用来设置主题的,Seaborn有五个预设好的主题: darkgrid , whitegrid , dark , white ,和 ticks  默认: darkgrid
  • set( )通过设置参数可以用来设置背景,调色板等,更加常用。
sns.set(style="white", palette="muted", color_codes=True)     #set( )设置主题,调色板更常用 
  • distplot( )为hist加强版;
sns.distplot(df_iris['petal length'], ax = axes[0], kde = True, rug = True)        # kde 密度曲线  rug 边际毛毯 
  • kdeplot( )为密度曲线图 
sns.kdeplot(df_iris['petal length'], ax = axes[1], shade=True)                     # shade  阴影 

 

关系图

relplot([x, y, hue, size, style, data, row, …]) Figure-level interface for drawing relational plots onto a FacetGrid.
scatterplot([x, y, hue, style, size, data, …]) 散点图:Draw a scatter plot with possibility of several semantic groupings.
lineplot([x, y, hue, size, style, data, …]) Draw a line plot with possibility of several semantic groupings.

分类图

catplot([x, y, hue, data, row, col, …]) Figure-level interface for drawing categorical plots onto a FacetGrid.
stripplot([x, y, hue, data, order, …]) Draw a scatterplot where one variable is categorical.
swarmplot([x, y, hue, data, order, …]) Draw a categorical scatterplot with non-overlapping points.
boxplot([x, y, hue, data, order, hue_order, …]) Draw a box plot to show distributions with respect to categories.
violinplot([x, y, hue, data, order, …]) Draw a combination of boxplot and kernel density estimate.
boxenplot([x, y, hue, data, order, …]) Draw an enhanced box plot for larger datasets.
pointplot([x, y, hue, data, order, …]) Show point estimates and confidence intervals using scatter plot glyphs.
barplot([x, y, hue, data, order, hue_order, …]) Show point estimates and confidence intervals as rectangular bars.
countplot([x, y, hue, data, order, …]) Show the counts of observations in each categorical bin using bars.

分布图

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.

回归图

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.

矩阵图

heatmap(data[, vmin, vmax, cmap, center, …]) 热点图:Plot rectangular data as a color-encoded matrix.
clustermap(data[, pivot_kws, method, …]) Plot a matrix dataset as a hierarchically-clustered heatmap.

多绘图网格

小平面网格

FacetGrid(data[, row, col, hue, col_wrap, …]) Multi-plot grid for plotting conditional relationships.
FacetGrid.map(func, *args, **kwargs) Apply a plotting function to each facet’s subset of the data.
FacetGrid.map_dataframe(func, *args, **kwargs) Like .map but passes args as strings and inserts data in kwargs.

成对网格

PairGrid(data[, hue, hue_order, palette, …]) Subplot grid for plotting pairwise relationships in a dataset.
PairGrid.map(func, **kwargs) Plot with the same function in every subplot.
PairGrid.map_diag(func, **kwargs) Plot with a univariate function on each diagonal subplot.
PairGrid.map_offdiag(func, **kwargs) Plot with a bivariate function on the off-diagonal subplots.
PairGrid.map_lower(func, **kwargs) Plot with a bivariate function on the lower diagonal subplots.
PairGrid.map_upper(func, **kwargs) Plot with a bivariate function on the upper diagonal subplots.

联合网格

JointGrid(x, y[, data, height, ratio, …]) Grid for drawing a bivariate plot with marginal univariate plots.
JointGrid.plot(joint_func, marginal_func[, …]) Shortcut to draw the full plot.
JointGrid.plot_joint(func, **kwargs) Draw a bivariate plot of x and y.
JointGrid.plot_marginals(func, **kwargs) Draw univariate plots for x and y separately.

风格控制

set([context, style, palette, font, …]) Set aesthetic parameters in one step.
axes_style([style, rc]) Return a parameter dict for the aesthetic style of the plots.
set_style([style, rc]) Set the aesthetic style of the plots.
plotting_context([context, font_scale, rc]) Return a parameter dict to scale elements of the figure.
set_context([context, font_scale, rc]) Set the plotting context parameters.
set_color_codes([palette]) Change how matplotlib color shorthands are interpreted.
reset_defaults() Restore all RC params to default settings.
reset_orig() Restore all RC params to original settings (respects custom rc).

调色板Color palettes

set_palette(palette[, n_colors, desat, …]) Set the matplotlib color cycle using a seaborn palette.
color_palette([palette, n_colors, desat]) Return a list of colors defining a color palette.
husl_palette([n_colors, h, s, l]) Get a set of evenly spaced colors in HUSL hue space.
hls_palette([n_colors, h, l, s]) Get a set of evenly spaced colors in HLS hue space.
cubehelix_palette([n_colors, start, rot, …]) Make a sequential palette from the cubehelix system.
dark_palette(color[, n_colors, reverse, …]) Make a sequential palette that blends from dark to color.
light_palette(color[, n_colors, reverse, …]) Make a sequential palette that blends from light to color.
diverging_palette(h_neg, h_pos[, s, l, sep, …]) Make a diverging palette between two HUSL colors.
blend_palette(colors[, n_colors, as_cmap, input]) Make a palette that blends between a list of colors.
xkcd_palette(colors) Make a palette with color names from the xkcd color survey.
crayon_palette(colors) Make a palette with color names from Crayola crayons.
mpl_palette(name[, n_colors]) Return discrete colors from a matplotlib palette.

调色板控件

choose_colorbrewer_palette(data_type[, as_cmap]) Select a palette from the ColorBrewer set.
choose_cubehelix_palette([as_cmap]) Launch an interactive widget to create a sequential cubehelix palette.
choose_light_palette([input, as_cmap]) Launch an interactive widget to create a light sequential palette.
choose_dark_palette([input, as_cmap]) Launch an interactive widget to create a dark sequential palette.
choose_diverging_palette([as_cmap]) Launch an interactive widget to choose a diverging color palette.

效用函数 Utility functions

load_dataset(name[, cache, data_home]) Load a dataset from the online repository (requires internet).
despine([fig, ax, top, right, left, bottom, …]) Remove the top and right spines from plot(s).
desaturate(color, prop) Decrease the saturation channel of a color by some percent.
saturate(color) Return a fully saturated color with the same hue.
set_hls_values(color[, h, l, s]) Independently manipulate the h, l, or s channels of a color.

你可能感兴趣的:(Python)