【问题标题】:plotting tabular data with holoviews用全息视图绘制表格数据
【发布时间】:2017-11-23 18:55:28
【问题描述】:

我想绘制这样的数据

 |   |abstime                |hostname   |type   |id |cpu    |mem    |reltime|
 -----------------------------------------------------------------------------
 |0  |2017-06-21 02:45:39    |hw03       |ps     |0  |16.0   |0.0    |0:00.08|
 |1  |2017-06-21 02:45:43    |hw03       |ps     |0  |98.0   |0.1    |0:02.23|
 |2  |2017-06-21 02:45:48    |hw03       |ps     |0  |1591.0 |0.1    |0:21.09|
 |3  |2017-06-21 02:45:52    |hw03       |ps     |0  |0.0    |0.1    |0:38.35|
 |4  |2017-06-21 02:45:57    |hw03       |ps     |0  |0.0    |0.1    |1:01.41|

使用 Holoviews Python 包。

我正在尝试创建多个这样的小部件:

下拉(主机名) 线图(abstime vs cpu)下拉(类型) 按 id 着色 下拉(主机名) 线图(abstime vs cpu)下拉(类型) 下拉(ID) 线图(abstime vs cpu)下拉(主机名) 按类型着色

我认为理想情况下是使用 hv.Table 之类的东西,然后使用 .to.curve 和其他 Holoviews 技术对其进行切片和切块。

我正在尝试遵循示例和教程 - 但它们都没有在列中重复,所以我很困惑如何分组,我的 kdims、vdims 和 cdims 应该是什么......

例如:

table=hv.Table(df,kdims=['abstime','reltime','hostname','type','id'],vdims=['cpu','mem'])

print(table)
#:Table   [abstime,reltime,hostname,type,id]   (cpu,mem)

table[None,None,{'hw03'},{'ps'},None].to.curve('abstime','cpu')

这在最后一次调用时给了我一个错误:

AttributeError: 'DataFrame' object has no attribute 'itertuple'

高度赞赏任何相关示例!

顺便说一句,我的表 df 是 Dask Dataframe(许多 CSV 文件),所以如果这很重要,我会依赖延迟计算...

谢谢!

【问题讨论】:

  • 这似乎是 HoloViews 中的一个简单错字,我已在此处进行了修复:github.com/ioam/holoviews/pull/1593 该修复将在下一个版本中提供,即 HoloViews 1.8,稍后将提供今天在 1.8dev3 版本中可以使用 conda install -c ioam/label/dev holoviews 安装。

标签: python csv plot dask holoviews


【解决方案1】:

为了获得下拉列表,我扩展了您的数据集以包含具有另一个主机名的记录:

|abstime |主机名|类型|id|cpu |内存|相对时间 0| 2017-06-2102:45:39|hw03 |ps |0 |16.0 |0.0| 0:00.08 1| 2017-06-2102:45:43|hw03 |ps |0 |98.0 |0.1| 0:02.23 2| 2017-06-2102:45:48|hw03 |ps |0 |1591.0|0.1| 0:21.09 3| 2017-06-2102:45:52|hw03 |ps |0 |0.0 |0.1| 0:38.35 4| 2017-06-2102:45:57|hw04 |ps |0 |0.0 |0.1| 1:01.41 5| 2017-06-2102:45:39|hw04 |ps |0 |16.0 |0.0| 0:00.08 6| 2017-06-2102:45:43|hw04 |ps |0 |98.0 |0.1| 0:02.23 7| 2017-06-2102:45:48|hw04 |ps |0 |1591.0|0.1| 0:21.09 8| 2017-06-2102:45:52|hw04 |ps |0 |0.0 |0.1| 0:38.35 9| 2017-06-2102:45:57|hw04 |ps |0 |0.0 |0.1| 1:01.41

我使用的是 Pandas 而不是 dask,但原理是一样的:

import pandas as pd
import holoviews as hv
hv.extension('bokeh')
d=pd.read_csv('so.csv')
# Create a holoviews dataset from any of a number of data structures.
ds=hv.Dataset(d)
display(ds.data)
#Now create a table from just the columns that we want. Otherwise
#You will get more dropdowns than you might want in the holomap.   
tb=hv.Table(ds,kdims=['abstime','hostname','type'],vdims='cpu')
display(tb)
#This is a dimensioned element.
hv.HoloMap(tb.to.curve(kdims=['abstime'],vdims='cpu'))

这将为您提供主机名下拉菜单,并显示 abstime 与 cpu 的曲线。如果您的数据有不止一种类型,那么还会有第二个下拉小部件。

【讨论】:

    猜你喜欢
    • 2018-06-20
    • 2020-02-17
    • 2012-06-08
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多