I’ve been stumbling my way through reimplementations in hvplot - holoviews - panel, as I kept finding limitations at each layer (is there any place where I could give feedback on the docs?).
But now I’m stuck. In Holoviews (using hvplot.show()
) I had a single Legend controlling mute functionality across multiple plots - see first plot served by the attached example.
But I had to move to Panels for more layout flexibility, and now (with gspec.show()
) each plot’s Legend works independently, which is confusing because the axis do work together - see 2nd plot served by the attached example.
Is there any way I can “reconnect” or “unify” the Legends in the Panel version, so I can keep only one Legend?
Similarly for the Bokeh toolbar: in Panel it’s now independent for each subplot. Can they be unified?
Also, I’d be grateful for any hint on how to disable vertical scrolling in the spikes plot.
import numpy as np
import holoviews as hv
import hvplot
from holoviews import opts
hv.extension('bokeh')
import panel as pn
pn.extension()
N = 100
series = ['fee', 'fie', 'foo']
NSERIES = len(series)
data = {}
hists = {}
spikes = {}
bars = {}
bins = np.linspace(-5,5,20)
for i,s in enumerate(series):
data[s] = i+ np.random.randn(N)
frequencies, edges = np.histogram(data[s], bins)
hists[s] = hv.Histogram((edges, frequencies))
spikesV = [s]*N # for the hover tool
spikes[s] = hv.Spikes((data[s],spikesV), kdims='x').opts(position=i)
bars[s] = hv.Bars(([s],2*i+np.random.randn(1)),vdims=['Frequency'])
hists_plot = hv.NdOverlay(hists)
hists_plot.opts(
opts.Histogram(alpha=0.7, responsive=True, height=500, tools=['hover'],
autorange='y',ylim=(0,None), xlim=(-5,5),padding=(0, (0, 0.1)),show_legend=True, muted=True),
opts.NdOverlay(tools=['hover'],
autorange='y',ylim=(0,None), xlim=(-5,5),padding=(0, (0, 0.1)),show_legend=True),
)
spikes_plot = hv.NdOverlay(spikes).opts(yticks=[((i+1)-0.5, s) for i,s in enumerate(series)])
spikes_plot.opts(
opts.Spikes(spike_length=1,line_alpha=1,responsive=True, height=50+NSERIES*20,color=hv.Cycle(),ylim=(0,NSERIES),autorange=None,tools=['hover'],yaxis='right', muted=True),
opts.NdOverlay(autorange=None,ylim=(0,NSERIES),tools=['hover'],show_legend=False),
)
bars_plot = hv.NdOverlay(bars)
bars_plot.opts(
opts.Bars(alpha=0.7, responsive=True, height=500, tools=['hover'],
autorange='y',ylim=(0,None),padding=(0, (0, 0.1)), muted=True),
opts.NdOverlay(tools=['hover'],
autorange='y',ylim=(0,None),padding=(0, (0, 0.1)),show_legend=False),
)
# HOLOVIEWS RENDERING
hs_plot = hists_plot + spikes_plot + bars_plot
hs_plot.cols(1)
hvplot.show(hs_plot)
# PANEL RENDERING
gspec = pn.GridSpec(sizing_mode='stretch_both', min_height=800)
mc = 4 # max col
mr = 5 # max row
gspec[0:mc, 0:mr] = pn.pane.HoloViews(hists_plot)
gspec[0:mc, mr] = pn.pane.HoloViews(bars_plot)
gspec[mc , 0:mr] = pn.pane.HoloViews(spikes_plot)
gspec.show()