直方图\密度图

直方图和密度图一般用于分布数据的可视化。

distplot

用于绘制单变量的分布图,包括直方图和密度图。

sns.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,
)
Docstring:
Flexibly plot a univariate distribution of observations. This function combines the matplotlib ``hist`` function (with automatic
calculation of a good default bin size) with the seaborn :func:`kdeplot`
and :func:`rugplot` functions. It can also fit ``scipy.stats``
distributions and plot the estimated PDF over the data. Parameters
---------- a : Series, 1d-array, or list.
Observed data. If this is a Series object with a ``name`` attribute,
the name will be used to label the data axis.
bins : argument for matplotlib hist(), or None, optional
Specification of hist bins, or None to use Freedman-Diaconis rule.
hist : bool, optional
Whether to plot a (normed) histogram.
kde : bool, optional
Whether to plot a gaussian kernel density estimate.
rug : bool, optional
Whether to draw a rugplot on the support axis.
fit : random variable object, optional
An object with `fit` method, returning a tuple that can be passed to a
`pdf` method a positional arguments following an grid of values to
evaluate the pdf on.
{hist, kde, rug, fit}_kws : dictionaries, optional
Keyword arguments for underlying plotting functions.
color : matplotlib color, optional
Color to plot everything but the fitted curve in.
vertical : bool, optional
If True, observed values are on y-axis.
norm_hist : bool, optional
If True, the histogram height shows a density rather than a count.
This is implied if a KDE or fitted density is plotted.
axlabel : string, False, or None, optional
Name for the support axis label. If None, will try to get it
from a.namel if False, do not set a label.
label : string, optional
Legend label for the relevent component of the plot
ax : matplotlib axis, optional
if provided, plot on this axis Returns
-------
ax : matplotlib Axes
Returns the Axes object with the plot for further tweaking. See Also
--------
kdeplot : Show a univariate or bivariate distribution with a kernel
density estimate.
rugplot : Draw small vertical lines to show each observation in a
distribution.
kdeplot

用于绘制单变量或双变量的核密度图。

sns.kdeplot(
data,
data2=None,
shade=False,
vertical=False,
kernel='gau',
bw='scott',
gridsize=100,
cut=3,
clip=None,
legend=True,
cumulative=False,
shade_lowest=True,
cbar=False,
cbar_ax=None,
cbar_kws=None,
ax=None,
**kwargs,
)
Docstring:
Fit and plot a univariate or bivariate kernel density estimate. Parameters
----------
data : 1d array-like
Input data.
data2: 1d array-like, optional
Second input data. If present, a bivariate KDE will be estimated.
shade : bool, optional
If True, shade in the area under the KDE curve (or draw with filled
contours when data is bivariate).
vertical : bool, optional
If True, density is on x-axis.
kernel : {'gau' | 'cos' | 'biw' | 'epa' | 'tri' | 'triw' }, optional
Code for shape of kernel to fit with. Bivariate KDE can only use
gaussian kernel.
bw : {'scott' | 'silverman' | scalar | pair of scalars }, optional
Name of reference method to determine kernel size, scalar factor,
or scalar for each dimension of the bivariate plot. Note that the
underlying computational libraries have different interperetations
for this parameter: ``statsmodels`` uses it directly, but ``scipy``
treats it as a scaling factor for the standard deviation of the
data.
gridsize : int, optional
Number of discrete points in the evaluation grid.
cut : scalar, optional
Draw the estimate to cut * bw from the extreme data points.
clip : pair of scalars, or pair of pair of scalars, optional
Lower and upper bounds for datapoints used to fit KDE. Can provide
a pair of (low, high) bounds for bivariate plots.
legend : bool, optional
If True, add a legend or label the axes when possible.
cumulative : bool, optional
If True, draw the cumulative distribution estimated by the kde.
shade_lowest : bool, optional
If True, shade the lowest contour of a bivariate KDE plot. Not
relevant when drawing a univariate plot or when ``shade=False``.
Setting this to ``False`` can be useful when you want multiple
densities on the same Axes.
cbar : bool, optional
If True and drawing a bivariate KDE plot, add a colorbar.
cbar_ax : matplotlib axes, optional
Existing axes to draw the colorbar onto, otherwise space is taken
from the main axes.
cbar_kws : dict, optional
Keyword arguments for ``fig.colorbar()``.
ax : matplotlib axes, optional
Axes to plot on, otherwise uses current axes.
kwargs : key, value pairings
Other keyword arguments are passed to ``plt.plot()`` or
``plt.contour{f}`` depending on whether a univariate or bivariate
plot is being drawn. Returns
-------
ax : matplotlib Axes
Axes with plot. See Also
--------
distplot: Flexibly plot a univariate distribution of observations.
jointplot: Plot a joint dataset with bivariate and marginal distributions.
rugplot

用于在坐标轴上绘制数据点,显示数据分布情况,一般结合distplot和kdeplot一起使用。

sns.rugplot(a, height=0.05, axis='x', ax=None, **kwargs)
Docstring:
Plot datapoints in an array as sticks on an axis. Parameters
----------
a : vector
1D array of observations.
height : scalar, optional
Height of ticks as proportion of the axis.
axis : {'x' | 'y'}, optional
Axis to draw rugplot on.
ax : matplotlib axes, optional
Axes to draw plot into; otherwise grabs current axes.
kwargs : key, value pairings
Other keyword arguments are passed to ``LineCollection``. Returns
-------
ax : matplotlib axes
The Axes object with the plot on it.
一维数据可视化
distplot()
#直方图distplot()
#参数:bins->箱数, hist->是否显示箱曲线, kde->是否显示密度曲线, norm_hist->直方图是否按照密度来表示
#rug->是否显示数据分布情况, vertical->是否水平显示,label->设置图例, axlabel->设置x轴标注 rs = np.random.RandomState(123) #设定随机种子
datas = pd.Series(rs.randn(100)) #创建包含100个随机数据的Series
sns.distplot(a=datas, bins=10, hist=True, kde=False, norm_hist=False,
rug=True, vertical=False, color='r', label='distplot', axlabel='x')
plt.legend()

#kde=True设置密度曲线
sns.distplot(a=datas, bins=10, hist=True, kde=True, norm_hist=False,
rug=True, vertical=False, color='r', label='distplot', axlabel='x')
plt.legend()

#norm_hist设置直方图按照密度曲线显示,实现hist=True 加 kde=True 共同的效果
sns.distplot(a=datas, bins=10, norm_hist=True,
rug=True, vertical=False, color='r', label='distplot', axlabel='x')
plt.legend()

#rug=False不显示频率分布,vertical=False横向放置图形
sns.distplot(a=datas, bins=10, norm_hist=True,
rug=False, vertical=False, color='r', label='distplot', axlabel='x')
plt.legend()

#总体参数设置
sns.distplot(datas, rug=True,
#rug_kws设置数据频率分布颜色
rug_kws={'color':'y'},
#kde_kws设置密度曲线颜色、线宽、标注、线型
kde_kws={'color':'r', 'lw':1, 'label':'KDE', 'linestyle':'--'},
#hist_kws设置箱子的风格、线宽、透明度、颜色
#histtype包括’bar'、‘barstacked’,'step','stepfilled'
hist_kws={'histtype':'step', 'linewidth':1, 'alpha':1, 'color':'k'})

kdeplot()
#密度图 -- kdeplot()

#shade--> 填充设置
sns.kdeplot(datas, shade=True, color='r', vertical=False)

#bw --> 拟合参数
sns.kdeplot(datas, bw=5, label='bw:0.2',
linestyle='-', linewidth=1.2, alpha=0.5) sns.kdeplot(datas, bw=20, label='bw:2',
linestyle='-', linewidth=1.2, alpha=0.5) #rugplot()设置频率分布图
sns.rugplot(datas, height=0.1, color='k', alpha=0.5)

二维数据可视化
kdeplot()
#二维数据密度图

rs = np.random.RandomState(12345)
df = pd.DataFrame(rs.randn(100,2),
columns=['A','B']) sns.kdeplot(df['A'],df['B'],
cbar = True, #设置显示颜色图例条
shade = True, #是否填充
cmap = 'Reds', #设置调色盘
shade_lowest = 'False', #设置最外围颜色是否显示
n_levels = 10) #设置曲线个数(越多越平滑) #分别设置x,y轴的频率分布图
sns.rugplot(df['A'], color='y', axis='x', alpha=0.5)
sns.rugplot(df['B'], color='k', axis='y', alpha=0.5)

sns.kdeplot(df['A'],df['B'],
cbar = True,
shade = False, #不填充
cmap = 'Reds',
shade_lowest = 'False',
n_levels = 10) #分别设置x,y轴的频率分布图
sns.rugplot(df['A'], color='y', axis='x', alpha=0.5)
sns.rugplot(df['B'], color='k', axis='y', alpha=0.5)

sns.kdeplot(df['A'],df['B'],
cbar = True,
shade = True,
cmap = 'Reds',
# shade_lowest = 'False', #设置最外围颜色是否显示,与shade配合使用
n_levels = 10) #设置曲线个数(越多越平滑) #分别设置x,y轴的频率分布图
sns.rugplot(df['A'], color='y', axis='x', alpha=0.5)
sns.rugplot(df['B'], color='k', axis='y', alpha=0.5)

sns.kdeplot(df['A'],df['B'],
cbar = True,
shade = True,
cmap = 'Reds',
# shade_lowest = 'False', #设置最外围颜色是否显示,与shade配合使用
n_levels = 100) #设置曲线个数(越多则边界渐变越平滑) #分别设置x,y轴的频率分布图
sns.rugplot(df['A'], color='y', axis='x', alpha=0.5)
sns.rugplot(df['B'], color='k', axis='y', alpha=0.5)

#多个密度图

#创建两个DataFrame数组
rs1 = np.random.RandomState(12)
rs2 = np.random.RandomState(21)
df1 = pd.DataFrame(rs1.randn(100,2)+2, columns=['A','B'])
df2 = pd.DataFrame(rs2.randn(100,2)-2, columns=['A','B']) #创建密度图
sns.kdeplot(df1['A'], df1['B'], cmap='Greens',
shade=True, shade_lowest=False)
sns.kdeplot(df2['A'], df2['B'], cmap='Blues',
shade=True, shade_lowest=False)

Seaborn分布数据可视化---直方图/密度图的更多相关文章

  1. Python图表数据可视化Seaborn:1. 风格| 分布数据可视化-直方图| 密度图| 散点图

    conda  install seaborn  是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...

  2. seaborn分布数据可视化:直方图|密度图|散点图

    系统自带的数据表格(存放在github上https://github.com/mwaskom/seaborn-data),使用时通过sns.load_dataset('表名称')即可,结果为一个Dat ...

  3. Echarts数据可视化series-radar雷达图,开发全解+完美注释

    全栈工程师开发手册 (作者:栾鹏) Echarts数据可视化开发代码注释全解 Echarts数据可视化开发参数配置全解 6大公共组件详解(点击进入): title详解. tooltip详解.toolb ...

  4. Echarts数据可视化series-line线图,开发全解+完美注释

    全栈工程师开发手册 (作者:栾鹏) Echarts数据可视化开发代码注释全解 Echarts数据可视化开发参数配置全解 6大公共组件详解(点击进入): title详解. tooltip详解.toolb ...

  5. Echarts数据可视化series-graph关系图,开发全解+完美注释

    全栈工程师开发手册 (作者:栾鹏) Echarts数据可视化开发代码注释全解 Echarts数据可视化开发参数配置全解 6大公共组件详解(点击进入): title详解. tooltip详解.toolb ...

  6. seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化

    一.线性关系数据可视化lmplot( ) 表示对所统计的数据做散点图,并拟合一个一元线性回归关系. lmplot(x, y, data, hue=None, col=None, row=None, p ...

  7. Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)

    直方图用于展示数据的分布情况,x轴是一个连续变量,y轴是该变量的频次. 下面利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://d ...

  8. 用Python的Plotly画出炫酷的数据可视化(含各类图介绍,附代码)

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 我被狗咬了 在谈及数据可视化的时候,我们通常都会使用到matplo ...

  9. R绘图(1): 在散点图边缘加上直方图/密度图/箱型图

    当我们在绘制散点图的时候,可能会遇到点特别多的情况,这时点与点之间过度重合,影响我们对图的认知.为了更好地反映特征,我们可以加上点的密度信息,比如在原来散点所在的位置将密度用热图的形式呈现出来,再比如 ...

  10. python-两个筛子数据可视化(直方图)

    """ 作者:zxj 功能:模拟掷骰子,两个筛子数据可视化 版本:3.0 日期:19/3/24 """ import random impo ...

随机推荐

  1. 第120篇: DOM编程(常用操作、动态脚本、样式及动态表格)

    好家伙,我回来了, 本篇为<JS高级程序设计>第十四章"DOM编程"学习笔记   1.DOM编程 我们知道DOM是HTML文档的编程接口, 我们可以通过HTML代码实现 ...

  2. CDC作业历史记录无法删除问题

    背景 数据库开启CDC功能后,每天会生成大量的历史记录,即使达到参数"每个作业的最大历史记录"的阈值后也不会被删除,导致其它作业的历史记录被删除,无法查看以前的执行情况,非常不方便 ...

  3. 青少年CTF-Crypto(新手版本2.0,无factor1)

    凯撒大帝的征讨之路 题目: lnixoa{1x2azz7w8axyva7y1z2320vxy6v97v9a} 知识点:凯撒加密 我的题解: import base64 #shift得出移位多少,移位后 ...

  4. pycharm/Intellij idea双击打不开,没有反应,下列方法亲测有用!

    第一种方法: 看看你的微软C++运行库是不是误删了.....我就这么干过...以前有个软件捆绑这个 安装了 结果我后来给删了 ,导致我pycharm 和intellij idea全都打不开 !!!各位 ...

  5. foundation部分学习记录(更正更新中……)

    foundation部分学习记录(更新中--) 从FDB的角度看,它对上层只提供有序+事务+KV存储的抽象. 设计原则 模块化分割,尽量细分且模块之间相互解耦 例如事务系统内,其提交(write pa ...

  6. Caxa 二次开发 ObjectCRX-1 踩坑:环境配置以及 Helloworld

    绝了,坑是真 nm 的多,官方给的文档里到处都是坑. 用的环境 ObjectCRX,以下简称 objcrx. #1 安装环境 & 参考文档的大坑 #1.1 Caxa 提供的文档和环境安装包 首 ...

  7. KeyCastOW win10 屏幕显示按键 - 屏幕录像用

    KeyCastOW win10 屏幕显示按键 - 屏幕录像用 https://gitee.com/itas109/KeyCastOW/releases/v2.0.2.5-cn

  8. be动词 系动词 连缀动词 Linking Verb

    be动词 系动词 连缀动词 Linking Verb be 原型 am 第一人称单数形式 is 第三人称单数形式 are 第二人称单数和复数形式 been 过去分词 being 现在分词 was 第一 ...

  9. [SCOI 2009] 迷路 (矩阵快速幂)

    [SCOI 2009]迷路 传送门 问题描述 Windy 在有向图中迷路了. 该有向图有 \({N}\) 个节点,Windy 从节点 \({1}\) 出发,他必须恰好在 \({T}\) 时刻到达节点 ...

  10. stm32文件系统读写操作调试总结

    一 问题 最近使用到了文件系统的读写,中间遇到了一些问题值得深思.   二 源码解析 创建文件: FRESULT res; do { sprintf(filename,"/sensor_si ...