💡

holoviewsで複数のtime seriesデータをプロットする

2022/03/27に公開約1,500字

自分用のメモ

import holoviews as hv
import numpy as np
hv.extension('bokeh')
from holoviews.plotting.links import RangeToolLink

# Genrate Random Data
def randomDataGenerator(noOfSampleDataSets):
    for i in range(noOfSampleDataSets):
        res = np.random.randn(1000).cumsum()
        yield res



#generate all curves
def getCurves(n):
    for id, data in enumerate(randomDataGenerator(n)):
        curve = hv.Curve(data, label=f'{id}')
        yield curve



source_curves, target_curves  = [], []
for curve in getCurves(10):
    # Without relabel, the curve somehow shares the ranging properties. opts with clone=True doesn't help either.
    src = curve.relabel('').opts(width=800, height=150, yaxis=None, default_tools=[]) 
    tgt = curve.opts(width=800, labelled=['y'], tools=['hover'])
    source_curves.append(src)
    target_curves.append(tgt)     

# link RangeTool for the first curves in the list.
RangeToolLink(source_curves[0],target_curves[0])

#Overlay the source and target curves
overlaid_plot_src = hv.Overlay(source_curves).relabel('Source')    
overlaid_plot_tgt = hv.Overlay(target_curves).relabel('Target').opts(height=400, legend_position='right')

# layout the plot and render
layout = (overlaid_plot_tgt + overlaid_plot_src).cols(1)
layout.opts(merge_tools=False,shared_axes=False)

参考文献:https://stackoverflow.com/questions/57755227/how-to-use-rangetoollink-with-holoviews-in-an-overlayed-plot

Discussion

ログインするとコメントできます