# Xlim, NdOverlay and DynamicMap interaction

**URL:** <https://discourse.holoviz.org/t/xlim-ndoverlay-and-dynamicmap-interaction/3096>\
**Category:** Param\
**Created:** [November 17, 2021, 10:56pm UTC](https://discourse.holoviz.org/t/xlim-ndoverlay-and-dynamicmap-interaction/3096 "2021-11-17T22:56:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertoDF](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/robertodf/32/2450_2.png) [@RobertoDF](https://discourse.holoviz.org/u/RobertoDF)\
**Post date:** [November 17, 2021, 10:56pm UTC](https://discourse.holoviz.org/t/xlim-ndoverlay-and-dynamicmap-interaction/3096/1 "2021-11-17T22:56:26Z")

</div>

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

```auto
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:

```auto
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](https://discourse.holoviz.org/t/overlaying-holoviews-scatter-plots-output-by-parametrized-class/72/4)

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?

---

<div class="post-metadata">

**Author:** ![RobertoDF](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/robertodf/32/2450_2.png) [@RobertoDF](https://discourse.holoviz.org/u/RobertoDF)\
**Post date:** [November 17, 2021, 11:35pm UTC](https://discourse.holoviz.org/t/xlim-ndoverlay-and-dynamicmap-interaction/3096/2 "2021-11-17T23:35:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RobertoDF](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/robertodf/32/2450_2.png) [@RobertoDF](https://discourse.holoviz.org/u/RobertoDF)\
**Post date:** [November 17, 2021, 11:38pm UTC](https://discourse.holoviz.org/t/xlim-ndoverlay-and-dynamicmap-interaction/3096/3 "2021-11-17T23:38:37Z")

</div>

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

```auto
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](https://discourse.holoviz.org/t/how-to-update-limits-for-dynamicmap-overlays/2162/2)
