Description
I have a plot where I can hide certain data when I click the corresponding data on the legend (see example below).
However, I would like the y-axis of the graph to rescale whenever some data is hidden or not.
I know this is possible in bokeh with the object “DataRange1d”. But I don’t know how to use this object in holoviews.
Below I have the example for Bokeh and holoviews.
Example Bokeh
import pandas as pd
from bokeh.palettes import Spectral4
from bokeh.plotting import figure, show
from bokeh.models import DataRange1d
x = [1,2,1,2]
y = [1,2.5,3,4]
d = [1,1,2,2]
df = pd.DataFrame(list(zip(x, y, d)),columns =['x', 'y', 'd'])
b = figure(width=800, height=250)
b.title.text = 'Bokeh example'
colorList = ['red', 'green']
for i, j in enumerate(df['d'].unique()):
color=colorList[i]
name = 'p'+str(j)
b.scatter(df.loc[df['d']==j, 'x'], df.loc[df['d']==j, 'y'], line_width=2, color=color, alpha=0.8, legend_label=name)
b.legend.location = "bottom_right"
b.legend.click_policy="hide"
b.y_range = DataRange1d(only_visible=True)
show(b)
Example Holoviews
import pandas as pd
import holoviews as hv
x = [1,2,1,2]
y = [1,2.5,3,4]
d = [1,1,2,2]
df = pd.DataFrame(list(zip(x, y, d)),columns =['x', 'y', 'd'])
p1 = hv.Scatter(df[df['d']==1])
p2 = hv.Scatter(df[df['d']==2])
overlayDict = {'p1':p1, 'p2':p2}
p = hv.NdOverlay(overlayDict)
p.opts(legend_opts={"click_policy":'hide'}, legend_position='right')