- use Orthographic projection - set the central longitude - join using gv.HoloMap
This is also a use-case of when you would use GeoViews+HoloViews over hvplot (customized animation)
import os
import numpy as np
import xarray as xr
import geoviews as gv
import cartopy.crs as ccrs
gv.extension("bokeh")
# download and open data
os.system("wget https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis/Monthlies/surface_gauss/air.2m.mon.ltm.nc")
ds = xr.open_dataset("air.2m.mon.ltm.nc")[["air"]]
# create a plot for a single time step with the central longitude
def plot(ds_sel, central_lon):
# create a globe projection with the central longitude at 40 lat
projection = ccrs.Orthographic(central_longitude=central_lon, central_latitude=40)
# plot the data on the globe alongside coastline
return gv.Image(ds_sel, ["lon", "lat"], ["air"], crs=ccrs.PlateCarree()).opts(
projection=projection, global_extent=True
) * gv.feature.coastline().opts(projection=projection)
# create a dictionary of images for each time step
images = {}
central_lons = np.linspace(-180, 180, len(ds["time"]))
for time, central_lon in zip(ds["time"].values, central_lons):
images[time] = plot(ds.sel(time=time), central_lon)
# animate the images with a slider
hmap = gv.HoloMap(images, kdims=["time"]).opts(
"Image", height=400, width=600, colorbar=True, cmap="RdBu_r"
)
hmap
116. Want to display a rotating globe with your data?
The main components are:
- use Orthographic projection
- set the central longitude
- join using gv.HoloMap
This is also a use-case of when you would use GeoViews+HoloViews over hvplot (customized animation)