pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.63k stars 1.09k forks source link

First example on https://xarray.dev/ does not run #9812

Closed rsokolewicz closed 3 days ago

rsokolewicz commented 3 days ago

What happened?

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

I wanted to fix it and open a pull request, but I couldn't find where the home page is defined under /docs :')

What did you expect to happen?

No response

Minimal Complete Verifiable Example

No response

MVCE confirmation

Relevant log output

No response

Anything else we need to know?

No response

Environment

welcome[bot] commented 3 days ago

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!

TomNicholas commented 3 days ago

Thank you for flagging this! We should definitely fix it 😅

I couldn't find where the home page is defined under /docs :')

The xarray.dev website is actually defined in an entirely separate repo - https://github.com/xarray-contrib/xarray.dev

rsokolewicz commented 3 days ago

cool. I'll close this here and open a ticket there :)