If you zoom in and then change the slider a bit, the map extents resets
import panel as pn
import xarray as xr
import pandas as pd
import hvplot.pandas
import holoviews as hv
import cartopy.crs as ccrs
from random import randrange
tiles = hv.element.tiles.EsriImagery()
ds = xr.tutorial.open_dataset('air_temperature')
def plot(time):
df = ds.sel(time=time).to_dataframe()
num_points = randrange(5)
df = df.sample(num_points)
image = df.hvplot.points(
'lon', 'lat', color='air', geo=True, xlim=(-150, -50), ylim=(0, 50)
).opts(
projection=ccrs.GOOGLE_MERCATOR, width=1000, height=500)
return tiles * image
pn.interact(plot, time=ds['time'].values)
This seems to work, but I couldn’t find a way to get datetime
import panel as pn
import xarray as xr
import pandas as pd
import hvplot.pandas
import holoviews as hv
import cartopy.crs as ccrs
from random import randrange
tiles = hv.element.tiles.EsriImagery()
ds = xr.tutorial.open_dataset('air_temperature')
def plot(time):
df = ds.isel(time=time).to_dataframe()
num_points = randrange(5)
df = df.sample(num_points)
image = df.hvplot.points(
'lon', 'lat', color='air', geo=True, xlim=(-150, -50), ylim=(0, 50)
).opts(
projection=ccrs.GOOGLE_MERCATOR, width=1000, height=500)
return tiles * image
dmap = hv.DynamicMap(plot, kdims=['time']).redim.range(time=(0, 100))
dmap
This works
import panel as pn
import xarray as xr
import pandas as pd
import hvplot.pandas
import holoviews as hv
import cartopy.crs as ccrs
from random import randrange
tiles = hv.element.tiles.EsriImagery()
ds = xr.tutorial.open_dataset('air_temperature')
def plot(time):
df = ds.sel(time=time).to_dataframe()
num_points = randrange(100)
df = df.sample(num_points)
image = df.hvplot.points(
'lon', 'lat', color='air', geo=True, xlim=(-150, -50), ylim=(0, 50)
).opts(
projection=ccrs.GOOGLE_MERCATOR, width=1000, height=500)
return tiles * image
dmap = hv.DynamicMap(plot, kdims=['time']).redim.values(time=ds['time'].values)
dmap
Hi @ahuang11, do you still get this snippet to work (i.e. no extent resetting after zooming in and moving the time slider)? I’ve just tried it and saw the extent is being reset.
1 Like
Try:
import panel as pn
import xarray as xr
import pandas as pd
import geoviews as gv
import cartopy.crs as ccrs
from random import randrange
tiles = gv.tile_sources.EsriImagery()
ds = xr.tutorial.open_dataset('air_temperature')
def plot(time):
df = ds.sel(time=time).to_dataframe()
df = df.sample(randrange(5))
points = gv.Points(df, ["lon", "lat"]).opts(
projection=ccrs.GOOGLE_MERCATOR, global_extent=True, color="white")
return tiles * points
slider, points = pn.interact(plot, time=ds['time'].values)
layout = pn.Column(slider, points)
layout
1 Like
Thanks for your attempt, but no, it’s still not working unfortunately (panel 0.11.3, holoviews 1.14. Now the basemap is flickering while moving the slider. When I have time in the next weeks I’ll try to see how to get a working version of that.
import panel as pn
import xarray as xr
import pandas as pd
import geoviews as gv
import cartopy.crs as ccrs
from random import randrange
gv.extension("bokeh")
tiles = gv.tile_sources.EsriImagery()
ds = xr.tutorial.open_dataset('air_temperature')
slider = pn.widgets.DiscreteSlider(options=list(ds["time"].astype(str).values))
def plot(time):
df = ds.sel(time=time).to_dataframe()
df = df.sample(randrange(5))
points = gv.Points(df, ["lon", "lat"]).opts(
projection=ccrs.GOOGLE_MERCATOR, global_extent=True, color="white")
return tiles * points
points = gv.DynamicMap(pn.bind(plot, slider.param.value))
pn.Column(slider, points)
try this
1 Like
Thanks wonderful it works great!
2 Likes