Setting the alpha value of a
xdsi.hvplot(kind='quadmesh', rasterize=rasterize_toggle, data_aspect=1,
frame_height=800,cmap=cmap_sel, crs=ccrs.PlateCarree(),
projection=ccrs.PlateCarree(), project=True, geo=True,
coastline=True, global_extent=True)
seems to be harder than simply adding alpha in the hvplot
constructor or chainnig .opts(alpha=0.1)
at the end or even the .apply.opts(alpha=0.1)
. Is there a way for me to control the alpha of the quadmesh of the interactive xarray that I am currently plotting?
import panel as pn
import hvplot.xarray
import xarray as xr
pn.extension()
ds = xr.tutorial.open_dataset('air_temperature')
slider = pn.widgets.FloatSlider(name="alpha", start=0, end=1, value=0.5)
pn.Column(slider, ds.hvplot(x='lon', y='lat').apply.opts(alpha=slider.param.value))
Or even more efficient with JS:
import panel as pn
import hvplot.xarray
import xarray as xr
pn.extension()
ds = xr.tutorial.open_dataset('air_temperature')
slider = pn.widgets.FloatSlider(name="alpha", start=0, end=1, value=0.5)
plot = ds.hvplot.quadmesh(x='lon', y='lat')
slider.jslink(plot, value="glyph.fill_alpha")
pn.Column(slider, plot)
https://pydeas.readthedocs.io/en/latest/holoviz_interactions/panel_to_holoviews.html#Float-slider-for-glyph-fill-alpha
Thank you Mr. @ahuang11 . I am also trying to change the alpha on a composed Hvplot object so multiple Image Overlays with individual alpha values. Is there a way to avoid using labels to change a particular overlay’s alpha?
I think you might have to loop through the overlay.
1 Like