Customizing the Scrubber

I am wondering if there is a way to customize the scrubber that automatically appears in this example plot. I would imagine there is a way to do this using panel to add customizations, such as a plot/pause button, having the slider initial position at the last time, or being able to save gif’s. I haven’t found much documentation on this subject matter.

import xarray as xr
import hvplot.xarray

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air = air_ds.air
hvp=air.isel(time=slice(0,4)).hvplot(groupby='time', width=600)
hvp

import xarray as xr
import hvplot.xarray

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air = air_ds.air
hvp=air.isel(time=slice(0,4))
hvp.hvplot(groupby='time', width=600, widget_type='scrubber', widget_location='bottom')

This creates the scrubber

If you need more control, I think you need to use panel manually (if I’m not mistaken).

Actually, this works, but is a little unelegant :stuck_out_tongue:

import xarray as xr
import hvplot.xarray
import panel as pn

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air = air_ds.air
hvp=air.isel(time=slice(0,4))
plot, widget = hvp.hvplot(groupby='time', width=600, widget_type='scrubber', widget_location='bottom')
widget[1][0].value = len(hvp) - 1
display(pn.Row(plot, widget))

perhaps I used a bad example because I thought the feature would be a bit easier to translate between libraries but what is the syntax to get this to work in a geoviews sense. With this approach to plotting I’m not sure how to go about adding the syntax in that you added

kdims=['Lon','Lat','Time']
vdims = ['Station','Precipitation']

df_sel = {
    'Station': ['06C', '0R0', '10G'],
    'Time': ['2023-02-18 18:00:00+00:00', '2023-02-18 19:00:00+00:00', '2023-02-18 20:00:00+00:00'],
    'Lat': [41.9893, 31.2970, 40.5372],
    'Lon': [-88.1012, -89.8128, -81.9544],
    'Precipitation': [0.14, 0.13, 0.06],
}

df_sel = pd.DataFrame(df_sel)

ds = gv.Dataset(df_sel, kdims=kdims)
plot = (ds.to(gv.Points, ["Lon", "Lat"], vdims=vdims))

pn.panel(plot)

@ahuang11

may have got something working, but I feel as though there is likely a more efficient way to do this. Thoughts?

import panel as pn
import pandas as pd
import holoviews as hv
import geoviews as gv

pn.extension()

kdims=['Lon','Lat','Time']
vdims = ['Station','Precipitation']

df_sel = {
    'Station': ['06C', '0R0', '10G'],
    'Time': ['2023-02-18 18:00:00+00:00', '2023-02-18 19:00:00+00:00', '2023-02-18 20:00:00+00:00'],
    'Lat': [41.9893, 31.2970, 40.5372],
    'Lon': [-88.1012, -89.8128, -81.9544],
    'Precipitation': [0.14, 0.13, 0.06],
}

df_sel = pd.DataFrame(df_sel)

ds = gv.Dataset(df_sel, kdims=kdims)
plot = (ds.to(gv.Points, ["Lon", "Lat"], vdims=vdims))

player = pn.widgets.DiscretePlayer(name='Time', options=ds.data.Time.unique().tolist())

@pn.depends(Time=player.param.value)
def map_plot(Time):
    return ds.select(Time=Time).to(gv.Points, ["Lon", "Lat"], vdims=vdims)

pn.Column(player, map_plot)```