首页 > 解决方案 > 如何使用全息视图从直方图数据中显示 cdf?

问题描述

我正在使用带有散景后端的全息视图进行交互式可视化。我有一个带有边缘和频率数据的直方图。用累积分布 (cdf) 曲线覆盖直方图的优雅方法是什么?

我尝试使用该cumsum选项,hv.dim但不认为我做对了。帮助只是说,

Help on function cumsum in module holoviews.util.transform:
cumsum(self, **kwargs)

我的代码看起来像,

df_hist = pd.DataFrame(columns=['edges', 'freq'])
df_hist['edges'] = [-2, -1, 0, 1, 2]
df_hist['freq'] = [1, 3, 5, 3, 1]

hv.Histogram((df_hist.edges, df_hist.freq))

结果是直方图。

有没有类似...

hv.Histogram((df_hist.edges, df_hist.freq), type='cdf') ...显示累积分布?

标签: bokehholoviewshvplotholoviz

解决方案


一种可能的解决方案是使用histogram(cumulative=True),如下所示:

from holoviews.operation import histogram

histogram(hv.Histogram((df_hist.edges, df_hist.freq)), cumulative=True)

在此处转换元素的更多信息:http:
//holoviews.org/user_guide/Transforming_Elements.html


或者通过将原始数据转换为 hv.Dataset() 的更通用的解决方案:

import holoviews as hv
import seaborn as sns
hv.extension('bokeh')

iris = sns.load_dataset('iris')

hv_data = hv.Dataset(iris['petal_width'])

histogram(hv_data, cumulative=True)


但我更喜欢使用构建在 Holoviews 之上的库hvplot,甚至更多:

import hvplot
import hvplot.pandas

iris['petal_width'].hvplot.hist(cumulative=True)

hvplot 累积直方图


推荐阅读