Hello everybody,
My goal was to setup an interactive plot, in which the users themselves can decide to have the axis auto-adjust to the displayed data. And I thought that the option framewise = True (or False)
would be the solution to achieve that.
And it looks like framewise = True
is working, whereas framewise = False
in some cases is not.
In the first code example the interactive plot is behaving like I would expect, when setting framewise = False
.
import holoviews as hv
import pandas as pd
import panel as pn
import param
hv.extension("bokeh")
df = pd.DataFrame({'X': [0, 1, 2, 3, 4, 5],
'Var_A': [2, 1, 3, 6, 4, 2],
'Var_B': [8, 7, 5, 8, 5, 7]})
df_rolling = df.rolling(window=2, center=True).mean()
def update_plot(var):
plot = hv.Curve(df, ('X', 'Index'), var).opts(color='blue', tools=["hover"], framewise=False)
plot_rolling = hv.Curve(df_rolling, ('X', 'Index'), var).opts(color='red', tools=["hover"], framewise=False)
return plot * plot_rolling
def view_plot():
return pn.panel(hv.DynamicMap(pn.bind(update_plot, var=widget.param.choose_var)))
class Example_Widget(param.Parameterized):
choose_var = param.Selector(label='Choose Var:', default='Var_B', objects=['Var_A', 'Var_B'])
widget = Example_Widget()
# I read something about framewise not working in pn.Tabs so that's why I used a couple of Tabs here. But all o.k.
pn.Tabs(
('Tab A', pn.Tabs(
('Tab 1', pn.Row(widget.param, view_plot)),
('Tab 2', 'Hello'))),
('Tab B', 'Hello'),
)
The second code example is a bit different to the first: I have moved the functions inside the class (but that’s all):
import holoviews as hv
import pandas as pd
import panel as pn
import param
hv.extension("bokeh")
df = pd.DataFrame({'X': [0, 1, 2, 3, 4, 5],
'Var_A': [2, 1, 3, 6, 4, 2],
'Var_B': [8, 7, 5, 8, 5, 7]})
df_rolling = df.rolling(window=2, center=True).mean()
class Example_Widget(param.Parameterized):
choose_var = param.Selector(label='Choose Var:', default='Var_B', objects=['Var_A', 'Var_B'])
def update_plot(self, var):
plot = hv.Curve(df, ('X', 'Index'), var).opts(color='blue', tools=["hover"], framewise=False)
plot_rolling = hv.Curve(df_rolling, ('X', 'Index'), var).opts(color='red', tools=["hover"], framewise=False)
return plot * plot_rolling
def view_plot(self):
return pn.panel(hv.DynamicMap(pn.bind(self.update_plot, var=self.param.choose_var)))
widget = Example_Widget()
pn.Tabs(
('Tab A', pn.Tabs(
('Tab 1', pn.Row(widget.param, widget.view_plot)),
('Tab 2', 'Hello'))),
('Tab B', 'Hello'),
)
In this (the second) code example the plot is behaving like I would expect it to behave if I had set framewise = True
. But it’s set to False
. So I don’t understand why the plot auto-updates its axis-ranges. If someone could tell me what my mistake is or how I could stop the interactive plot to auto-adjust its axis-ranges, I would really appreciate that. (And if something is unclear, please let me know)
Best regards
(I ran the example code in a Jupyter-Notebook version 6.4.8, holoviews version 1.14.8, panel version 0.12.6, param version 1.12.0)