Xlim, NdOverlay and DynamicMap interaction

Hi,
I just run in a problem that I can’t seem to solve…
In this case xlim works flawlessly:

class test(param.Parameterized):
    start=param.Number(5, bounds=(1.0, 100.0))
    stop=param.Number(10, bounds=(1.0, 100.0))
    
    @param.depends("start", "stop")
    def plot(self):
        overlay = hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims='Time').opts(position=0.1*i)
                           for i in range(10)}).opts(yticks=[((i+1)*0.1-0.05, i) for i in range(10)])

        return overlay.opts(opts.Spikes(spike_length=0.1), opts.NdOverlay(height=200,show_legend=False, xlim=(self.start,self.stop)))

          
t = test(start=2, stop=9)
pn.Column(t.param, t.plot)

but if I wrap the class method in a DynamicMap xlim ceases to work:

class test(param.Parameterized):
    start=param.Number(5, bounds=(1.0, 100.0))
    stop=param.Number(10, bounds=(1.0, 100.0))
    
    @param.depends("start", "stop")
    def plot(self):
        overlay = hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims='Time').opts(position=0.1*i)
                           for i in range(10)}).opts(yticks=[((i+1)*0.1-0.05, i) for i in range(10)])

        return overlay.opts(opts.Spikes(spike_length=0.1),opts.NdOverlay(height=200,show_legend=False, xlim=(self.start,self.stop)))

          
t = test(start=2, stop=9)
pn.Column(t.param, hv.DynamicMap(t.plot))

I need the DynamicMap because I need to overlay methods like shown here at point 3 Overlaying Holoviews scatter plots output by parametrized class - #4 by jbednar

This problem happens only when the output of the method is a NdOverlay.

Does anybody knows how to get xlim to work in this case?

The problem is there also if I modify the code to use Overlay instead of NdOverlay.

The solution is to add “.opts(‘Spikes’, framewise=True, axiswise=True))” to the DynamicMap:

class test(param.Parameterized):
    start=param.Number(5, bounds=(1.0, 100.0))
    stop=param.Number(10, bounds=(1.0, 100.0))
    
    @param.depends("start", "stop")
    def plot(self):
        overlay = hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims='Time').opts(position=0.1*i)
                           for i in range(10)}).opts(yticks=[((i+1)*0.1-0.05, i) for i in range(10)])
        out = overlay.opts(opts.Spikes(spike_length=0.1),opts.NdOverlay(shared_axes=True, height=200,show_legend=False,xlim=(self.start,self.stop)))
        return out

          
t = test(start=2, stop=9)
pn.Column(t.param, hv.DynamicMap(t.plot).opts('Spikes', framewise=True, axiswise=True))

Thanks to How to update limits for DynamicMap overlays? - #2 by ahuang11

1 Like