# Separating hvplot plot and groupby widgets

**URL:** <https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313>\
**Category:** hvPlot\
**Created:** [June 7, 2024, 2:37pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313 "2024-06-07T14:37:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsignell](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/rsignell/32/5855_2.png) [@rsignell](https://discourse.holoviz.org/u/rsignell)\
**Post date:** [June 7, 2024, 2:37pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/1 "2024-06-07T14:37:09Z")

</div>

Following the [interactive time series example](https://discourse.holoviz.org/t/simple-panel-example-of-map-time-series-interaction-for-data-cube/1485/5) from @ahuang11, I have this code:

```python
import panel as pn
import xarray as xr
import holoviews as hv
import hvplot.xarray

pn.extension()
ds = xr.tutorial.open_dataset('air_temperature')
ds = ds.assign_coords(lon=(((ds.lon + 180) % 360) - 180), lat=ds.lat*1.0)
image, select = ds.hvplot('lon', 'lat', geo=True, cmap='viridis', widgets={'time':pn.widgets.Select})
stream = hv.streams.Tap(source=image.object, x=-88, y=40)

def timeseries(x, y):
    return ds.sel(lon=x, lat=y, method='nearest').hvplot('time', grid=True)

timeseries_plot = pn.bind(timeseries, x=stream.param.x, y=stream.param.y)
pn.Column(pn.Row(select), pn.Row(image, timeseries_plot))

```

which produces:

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/e/e9397bb3271eaf18b3911d53d77ec57bfc1b3731.png)

I thought I would enhance this by putting a marker on the map indicating where the user clicked to extract the time series.

I was able to create a `points` object with hvplot:

```python
import pandas as pd
import hvplot.pandas
df = pd.DataFrame({'lon':[-88.0], 'lat':[40], 'station':[0]})
station_plot = df.hvplot.points(x='lon', y='lat', geo=True, by='station', size=15)

```

which displays fine on it’s own, but when I try to overlay it on the `image` object above:

```python
image * station_plot

```

I get back:

```python-traceback
image * station_plot
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 image * station_plot

File /home/conda/global/b214724c3d4b6220c3e488e703fac35666e3afcee1879723c6ab99b60541a259-20240520-181650-902933-130-pangeo/lib/python3.11/site-packages/holoviews/core/ndmapping.py:1023, in UniformNdMapping. __rmul__ (self, other)
   1022 def __rmul__ (self, other):
-> 1023 return self. __mul__ (other, reverse=True)

TypeError: Overlayable. __mul__ () got an unexpected keyword argument 'reverse'

```

And when I tried to figure out what was wrong by simply plotting the `image` object, I see that it still has the widget attached:

```auto
image

```

produces:

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/e/e5d873cfa1aab2e8ab0b06163126a7df3b3d66ae.png)

If this is the problem, how do I remote the widget from this object?  
Or if not, how can I overlay my points object on the map?

In case it’s useful, the whole rendered notebook is here: [Jupyter Notebook Viewer (nbviewer.org)](https://nbviewer.org/gist/rsignell/9a062810cc16ef6812b5d7ea5e26780a)

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [June 7, 2024, 4:01pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/2 "2024-06-07T16:01:37Z")

</div>

Perhaps  
`image.object * station_plot`

---

<div class="post-metadata">

**Author:** ![rsignell](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/rsignell/32/5855_2.png) [@rsignell](https://discourse.holoviz.org/u/rsignell)\
**Post date:** [June 7, 2024, 5:16pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/3 "2024-06-07T17:16:53Z")

</div>

Yep! That works!

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/8/8b3f74a62149552f71fa88f517c51888efb3d4d6.png)

New notebook at: [Jupyter Notebook Viewer (nbviewer.org)](https://nbviewer.org/gist/rsignell/a6a14081d03daf3def655accd9aa0e8e)

---

<div class="post-metadata">

**Author:** ![Marc](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/marc/32/24_2.png) [@Marc](https://discourse.holoviz.org/u/Marc)\
**Post date:** [June 7, 2024, 6:48pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/4 "2024-06-07T18:48:02Z")

</div>

If I drop into Panel for the most part I can get the below working.

```python
import panel as pn
import xarray as xr
import holoviews as hv
import hvplot.xarray
import pandas as pd
import hvplot.pandas
import numpy as np
import datetime as dt
pn.extension()

ds = pn.cache(xr.tutorial.open_dataset)('air_temperature')
ds = ds.assign_coords(lon=(((ds.lon + 180) % 360) - 180), lat=ds.lat*1.0)
options = list(np.unique(ds.time))
select = pn.widgets.DiscreteSlider(options=options, name='Time')

def plot(time):
    return ds.sel(time=time, method="nearest").hvplot('lon', 'lat', geo=True, cmap='viridis')

image_dynamic_map = hv.DynamicMap(pn.bind(plot, select))
tap_stream = hv.streams.Tap(source=image_dynamic_map, x=-88, y=40)

df = pd.DataFrame({'lon':[-88.0], 'lat':[40], 'station':[0]})

station_plot = df.hvplot.points(x='lon', y='lat', geo=True, by='station', size=15, frame_height=200)
overlay = image_dynamic_map * station_plot

pn.Column(
    select,
    overlay,
    tap_stream,
).servable()

```

Getting the `select` widget having nice timestamps is left as an exercise to the reader (I could not figure it out).

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [June 7, 2024, 7:53pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/5 "2024-06-07T19:53:10Z")

</div>

`options = list(np.unique(ds.time))` can be

`options = ds["time"].dt.strftime("%Y-%m-%d %H:%M").values.tolist()`

---

<div class="post-metadata">

**Author:** ![rsignell](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/rsignell/32/5855_2.png) [@rsignell](https://discourse.holoviz.org/u/rsignell)\
**Post date:** [June 8, 2024, 12:29am UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/6 "2024-06-08T00:29:47Z")

</div>

@Marc I don’t see the station marker plotted on your solution either?  
(it seems the same result as cell [17] in [my solution](https://nbviewer.org/gist/rsignell/a6a14081d03daf3def655accd9aa0e8e)?)

Am I missing something?  
P.S. thanks for taking a look!

---

<div class="post-metadata">

**Author:** ![Marc](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/marc/32/24_2.png) [@Marc](https://discourse.holoviz.org/u/Marc)\
**Post date:** [June 8, 2024, 3:41pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/7 "2024-06-08T15:41:43Z")

</div>

Is the station marker not the little blue dot?

---

<div class="post-metadata">

**Author:** ![rsignell](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/rsignell/32/5855_2.png) [@rsignell](https://discourse.holoviz.org/u/rsignell)\
**Post date:** [June 8, 2024, 3:55pm UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/8 "2024-06-08T15:55:02Z")

</div>

Was there a blue dot on the map? I only saw it in the legend

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [June 9, 2024, 1:34am UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/9 "2024-06-09T01:34:18Z")

</div>

There is; I guess should be red.

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/2/28c9896c34bef9d32a6ad9c0df11ffdb656db57a.jpeg)

---

<div class="post-metadata">

**Author:** ![Marc](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/marc/32/24_2.png) [@Marc](https://discourse.holoviz.org/u/Marc)\
**Post date:** [June 9, 2024, 5:22am UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/10 "2024-06-09T05:22:45Z")

</div>

It was already there

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/7/7e04855647f860f6d802c0d3f3d89b457d842dd7.png)

---

<div class="post-metadata">

**Author:** ![rsignell](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/rsignell/32/5855_2.png) [@rsignell](https://discourse.holoviz.org/u/rsignell)\
**Post date:** [June 9, 2024, 10:12am UTC](https://discourse.holoviz.org/t/separating-hvplot-plot-and-groupby-widgets/7313/11 "2024-06-09T10:12:51Z")

</div>

I’m so sorry guys. Super embarrassing! I’ve selected Andrew’s original reply as the solution and edited my response. Kind of wish we could delete everything after that! 🙂
