Is there another way to set the xlim
, ylim
of a plot interactively without using the pn.bind
function? It seems that there should be a way using the redim
method of DynamicMap
but it is escaping me.
Below is a working example using pn.bind
.
import numpy as np
import pandas as pd
from holoviews import opts
import holoviews as hv
import panel as pn
pn.extension()
hv.extension('bokeh')
opts.defaults(opts.Scatter(
size=10,
show_grid=True,
framewise=True,
))
frames = [
pd.DataFrame(arr, columns=['x', 'y'])
for arr in np.random.randint(10, size=(10, 5, 2))
]
data_select = pn.widgets.Select(name='dataset',
options=frames,
value=frames[0])
xmin = pn.widgets.IntInput(name='xmin', value=0, step=1)
xmax = pn.widgets.IntInput(name='xmax', value=10, step=1)
ymin = pn.widgets.IntInput(name='ymin', value=0, step=1)
ymax = pn.widgets.IntInput(name='ymax', value=10, step=1)
def update_scatter(data, x0, x1, y0, y1):
return hv.Scatter(data).apply.opts(xlim=(x0, x1), ylim=(y0, y1))
scatter_dmap = hv.DynamicMap(
pn.bind(
update_scatter,
data=data_select.param.value,
x0=xmin.param.value,
x1=xmax.param.value,
y0=ymin.param.value,
y1=ymax.param.value,
), )
pn.Row(pn.Column(data_select, scatter_dmap),
pn.Column(xmin, xmax, ymin, ymax, width=100)).servable()