Seaborn包 画出好看的分布图(Python)

Seaborn是基于Matplotlib的Python数据可视化库,提供美观的主题和便于统计分析的图表。本文介绍了Seaborn的安装、优点,并通过distplot绘制单变量分布图,使用jointplot展示双变量分布,以及利用regression plots进行回归分析。此外,还探讨了histogram、kdeplot、rugplot和多维数据的可视化方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:http://www.open-open.com/lib/view/open1434182977754.html

           http://blog.youkuaiyun.com/pipisorry/article/details/49515745


Seaborn介绍

官方文档: https://pypi.python.org/pypi/seaborn/


Matplotlib是Python主要的绘图库。但是不建议你直接使用它,原因与不推荐你使用NumPy是一样的。虽然Matplotlib很强大,它本身就很复杂,你的图经过大量的调整才能变精致。因此,作为替代推荐一开始使用Seaborn。

Seaborn本质上使用Matplotlib作为核心库(就像Pandas对NumPy一样)。

Some of the features that seaborn offers are

  • Several built-in themes that improve on the default matplotlib aesthetics
  • Tools for choosing color palettes to make beautiful plots that reveal patterns in your data
  • Functions for visualizing univariate and bivariate distributions or for comparing them between subsets of data
  • Tools that fit and visualize linear regression models for different kinds of independent and dependent variables
  • Functions that visualize matrices of data and use clustering algorithms to discover structure in those matrices
  • A function to plot statistical timeseries data with flexible estimation and representation of uncertainty around the estimate
  • High-level abstractions for structuring grids of plots that let you easily build complex visualizations

seaborn的优点:

  1. 默认情况下就能创建赏心悦目的图表。(只有一点,默认不是jet colormap
  2. 创建具有统计意义的图
  3. 能理解pandas的DataFrame类型,所以它们一起可以很好地工作。

安装pip install seaborn

就算你不用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值