Skip to content

First example on https://xarray.dev/ homepage raises ImportError when running in widget #731

@rsokolewicz

Description

@rsokolewicz

There's an example on the home page: https://xarray.dev/ together with a notebook-like widget where the user is instructed to try out the code. The kernel however isn't preloaded with an installed version of matplotlib, so the example doesn't run:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 44
     41 data.mean(dim=["time", "lat"])
     43 # quick and convenient visualizations
---> 44 data.isel(lon=0).plot();
     46 # Pretty neat, eh? :)
     47 # For more, head over to the documentation page

File /lib/python3.12/site-packages/xarray/plot/accessor.py:48, in DataArrayPlotAccessor.__call__(self, **kwargs)
     46 @functools.wraps(dataarray_plot.plot, assigned=("__doc__", "__annotations__"))
     47 def __call__(self, **kwargs) -> Any:
---> 48     return dataarray_plot.plot(self._da, **kwargs)

File /lib/python3.12/site-packages/xarray/plot/dataarray_plot.py:309, in plot(darray, row, col, col_wrap, ax, hue, subplot_kws, **kwargs)
    305     plotfunc = hist
    307 kwargs["ax"] = ax
--> 309 return plotfunc(darray, **kwargs)

File /lib/python3.12/site-packages/xarray/plot/dataarray_plot.py:1571, in _plot2d.<locals>.newplotfunc(***failed resolving arguments***)
   1567 yplt, ylab_extra = _resolve_intervals_2dplot(yvalnp, plotfunc.__name__)
   1569 _ensure_plottable(xplt, yplt, zval)
-> 1571 cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(
   1572     plotfunc,
   1573     zval.data,
   1574     **locals(),
   1575     _is_facetgrid=kwargs.pop("_is_facetgrid", False),
   1576 )
   1578 if "contour" in plotfunc.__name__:
   1579     # extend is a keyword argument only for contour and contourf, but
   1580     # passing it to the colorbar is sufficient for imshow and
   1581     # pcolormesh
   1582     kwargs["extend"] = cmap_params["extend"]

File /lib/python3.12/site-packages/xarray/plot/utils.py:944, in _process_cmap_cbar_kwargs(func, data, cmap, colors, cbar_kwargs, levels, _is_facetgrid, **kwargs)
    942 cmap_kwargs.update((a, kwargs[a]) for a in cmap_args if a in kwargs)
    943 if not _is_facetgrid:
--> 944     cmap_params = _determine_cmap_params(**cmap_kwargs)
    945 else:
    946     cmap_params = {
    947         k: cmap_kwargs[k]
    948         for k in ["vmin", "vmax", "cmap", "extend", "levels", "norm"]
    949     }

File /lib/python3.12/site-packages/xarray/plot/utils.py:180, in _determine_cmap_params(plot_data, vmin, vmax, cmap, center, robust, extend, levels, filled, norm, _is_facetgrid)
    154 def _determine_cmap_params(
    155     plot_data,
    156     vmin=None,
   (...)
    165     _is_facetgrid=False,
    166 ):
    167     """
    168     Use some heuristics to set good defaults for colorbar and range.
    169 
   (...)
    178         Use depends on the type of the plotting function
    179     """
--> 180     import matplotlib as mpl
    182     if isinstance(levels, Iterable):
    183         levels = sorted(levels)

ModuleNotFoundError: No module named 'matplotlib'

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions