0

如何将以下绘图移植到 hvplot + datashader? 在此处输入图像描述

理想情况下,可以保留交互性,并且可以交互地选择特定的 device_id。(理想情况下使用画笔,即在选择异常点时,我希望能够过滤到基础系列,但如果这不起作用,也许从列表中选择它们也可以。请记住,这个列表可能相当长(在 1000 个元素的区域内))。

%pylab inline
import seaborn as sns; sns.set()
import pandas as pd
from pandas import Timestamp

d = pd.DataFrame({'metrik_0': {Timestamp('2020-01-01 00:00:00'): -0.5161200349325471,
  Timestamp('2020-01-01 01:00:00'): 0.6404118012330947,
  Timestamp('2020-01-01 02:00:00'): -1.0127867504877557,
  Timestamp('2020-01-01 03:00:00'): 0.25828987625529976,
  Timestamp('2020-01-01 04:00:00'): -2.486778084008076,
  Timestamp('2020-01-01 05:00:00'): -0.30695039872663826,
  Timestamp('2020-01-01 06:00:00'): -0.6570670310316116,
  Timestamp('2020-01-01 07:00:00'): 0.3274964731894147,
  Timestamp('2020-01-01 08:00:00'): -0.8624113311084097,
  Timestamp('2020-01-01 09:00:00'): 1.0832911260447902},
 'device_id': {Timestamp('2020-01-01 00:00:00'): 9,
  Timestamp('2020-01-01 01:00:00'): 1,
  Timestamp('2020-01-01 02:00:00'): 1,
  Timestamp('2020-01-01 03:00:00'): 9,
  Timestamp('2020-01-01 04:00:00'): 9,
  Timestamp('2020-01-01 05:00:00'): 9,
  Timestamp('2020-01-01 06:00:00'): 9,
  Timestamp('2020-01-01 07:00:00'): 1,
  Timestamp('2020-01-01 08:00:00'): 1,
  Timestamp('2020-01-01 09:00:00'): 9}})

fig, ax = plt.subplots()
for dev, df in d.groupby('device_id'):
    df.plot(y='metrik_0', ax=ax, label=dev)

到目前为止,我只能实现:

import pandas as pd
import datashader as ds
import numpy as np
import holoviews as hv

from holoviews import opts

from holoviews.operation.datashader import datashade, shade, dynspread, rasterize
from holoviews.operation import decimate

hv.extension('bokeh','matplotlib')

width = 1200
height = 400
curve = hv.Curve(d)

datashade(curve, cmap=["blue"], width=width, height=height).opts(width=width, height=height)

在此处输入图像描述

理想情况下,我也可以突出显示类似于 matplotlib: 的某些范围axvspan

4

1 回答 1

1

只要你想要达到 100,000 点左右,你就不需要 Datashader:

import pandas as pd
import hvplot.pandas
from pandas import Timestamp

df = pd.DataFrame(
       {'metrik_0': {
          Timestamp('2020-01-01 00:00:00'): -0.5161200349325471,
          Timestamp('2020-01-01 01:00:00'): 0.6404118012330947,
          Timestamp('2020-01-01 02:00:00'): -1.0127867504877557,
          Timestamp('2020-01-01 03:00:00'): 0.25828987625529976,
          Timestamp('2020-01-01 04:00:00'): -2.486778084008076,
          Timestamp('2020-01-01 05:00:00'): -0.30695039872663826,
          Timestamp('2020-01-01 06:00:00'): -0.6570670310316116,
          Timestamp('2020-01-01 07:00:00'): 0.3274964731894147,
          Timestamp('2020-01-01 08:00:00'): -0.8624113311084097,
          Timestamp('2020-01-01 09:00:00'): 1.0832911260447902},
        'device_id': {
          Timestamp('2020-01-01 00:00:00'): 9,
          Timestamp('2020-01-01 01:00:00'): 1,
          Timestamp('2020-01-01 02:00:00'): 1,
          Timestamp('2020-01-01 03:00:00'): 9,
          Timestamp('2020-01-01 04:00:00'): 9,
          Timestamp('2020-01-01 05:00:00'): 9,
          Timestamp('2020-01-01 06:00:00'): 9,
          Timestamp('2020-01-01 07:00:00'): 1,
          Timestamp('2020-01-01 08:00:00'): 1,
          Timestamp('2020-01-01 09:00:00'): 9}})

df.hvplot(by='device_id')

高压图

如果你想要 vspan,你可以从 HoloViews 获得:

import holoviews as hv
        
vspan = hv.VSpan(Timestamp('2020-01-01 04:00:00'),
                 Timestamp('2020-01-01 06:00:00'))
                 
df.hvplot(by='device_id') * vspan.opts(color='red')

跨度

如果你确实想要 Datashader,你可以拥有它,但如果没有进一步的工作,结果将无法选择:

df.hvplot(by='device_id', datashade=True, dynspread=True) * vspan.opts(color='red')

数据着色器

于 2020-10-15T20:32:54.373 回答