How do I save matplotlib backend opts without calling hv.extension('matplotlib')?

import hvplot.xarray
import holoviews as hv
import xarray as xr

ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
plot = ds.hvplot('lon', 'lat', dynamic=False).opts(fig_size=300)
hv.save(plot, 'testmaapl.html', resources='inline', backend='matplotlib')

I get these warnings:

WARNING:param.main: Option 'fig_size' for Image type not valid for selected backend ('bokeh'). Option only applies to following backends: ['matplotlib']
WARNING:param.main: Option 'fig_size' for Image type not valid for selected backend ('bokeh'). Option only applies to following backends: ['matplotlib']
WARNING:param.main: Option 'fig_size' for Image type not valid for selected backend ('bokeh'). Option only applies to following backends: ['matplotlib']

Because I flip flop between bokeh and matplotlib backends for different plots

e.g.
hv.extension(‘matplotlib’)
…plot some map with matplotlib

hv.extension(‘bokeh’)
…plot some map with bokeh

hv.extension(‘matplotlib’)
…again plot some map with matplotlib

You can provide the backend to the opts call:

plot = ds.hvplot('lon', 'lat', dynamic=False).opts(fig_size=300, backend='matplotlib')

You may also have to import the matplotlib backend though:

import holoviews.plotting.mpl
1 Like