The code below plots creates 3 plots with 6 parameters each. However, it seems to not allow more than 10 parameters to be plotted on a plot. Why would this be?
Change the second arg of create_generic_data()
from 6 to anything greater than 10, and it will only plot ten curves per plot:
import holoviews as hv
import panel as pn
from holoviews.operation.datashader import datashade, rasterize, dynspread
import datashader as ds
from math import sin
hv.extension('bokeh')
class MultiPlot:
def __init__(self, data, max_plots=6, plot_width=800, plot_height=150, cnorm="eq_hist", line_width=2,
pixel_ratio=2):
# Create a dictionary of all Curves. Top-level keys define number of subplots. Secondary-level keys point to
# each parameter to be plotted in each subplot. Time indices are aligned to start time.
curves_dict = {top_key: {sec_key: hv.Curve((sec_value.index.map(lambda x: (x-x[0]).total_seconds()),
sec_value.values), kdims=['Time'], vdims=['Value'])
for sec_key, sec_value in top_value.items()
}
for top_key, top_value in data.items()}
# Create list of overlay objects; one per top-level key, with each containing one Curve per secondary-key
self.overlay = [datashade(hv.NdOverlay(curves), line_width=line_width, pixel_ratio=pixel_ratio,
cnorm=cnorm, aggregator=ds.count()
).opts(width=plot_width, tools=['hover']).relabel(top_key)
for top_key, curves in curves_dict.items()]
# Create Layout to plot each Overlay figure in a single column
self.layout = hv.Layout(self.overlay).cols(1)
def show(self):
pn.serve(self.layout)
def create_generic_data(level1_parm_count, level2_parm_count, parm_sample_count):
"""Generates generic data dictionary"""
import pandas as pd
l1_parms = [f'L1P_{str(i)}' for i in range(level1_parm_count)]
l2_parms = [f'L2P_{str(i)}' for i in range(level2_parm_count)]
return {l1p: {l2p: pd.Series([sin(j/(parm_sample_count*.01)) * int(l2p[-1]) for j in range(parm_sample_count)],
index=pd.to_timedelta(range(parm_sample_count), unit='s'))
for l2p in l2_parms} for l1p in l1_parms}
if __name__ == '__main__':
# Optional creation of generic data set for troubleshooting. Args are (# of top keys, # of sec. keys, and # of
# points per Curve
data = create_generic_data(3, 6, 100000)
myplot = MultiPlot(data)
myplot.show()