如何将以下绘图移植到 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
。