bokeh - 如何使用全息视图从直方图数据中显示 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')
...显示累积分布?
解决方案
一种可能的解决方案是使用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)
推荐阅读
- django - “需要一个有效的文件名!” xhtml2pdf 与 Django
- android - 在 RecyclerView 项目按钮 OnClick 中使用共享首选项
- php - 添加 Google auth 2.0 应用程序需要什么范围?
- mongodb - MongoDB Shell - 打印数组的第一个元素
- html - 如何将文本元素设置为 0px 宽度?
- r - R从gam中提取时变平滑参数
- assembly - 在指令周期的获取阶段,事情是如何工作的?
- angular - 调用同级方法会引发“无法读取未定义的属性 'X'”
- typescript - 是否有在适当位置键入对象的简写?
- mysql - SQLSTATE [42S22]:找不到列:1054 'where 子句'(SQL 更新..)中的未知列 'id',其中 'id' 为空)