Guess the complementary dimension when only one is passed to pcolormesh by vnoel · Pull Request #1291 · pydata/xarray (original) (raw)
Because in 2D Plots we are guaranteed to have only 2 dims, but we can have an arbitrary number of auxiliary coordinates, in an arbitrary order. In my example above checking for coords would work, but this is not always the case. See:
import xarray as xr import numpy as np lon, lat = np.meshgrid(np.linspace(-20, 20, 5), np.linspace(0, 30, 4)) da = xr.DataArray(np.arange(20).reshape(4, 5), dims=['y', 'x'], coords = {'lat': (('y', 'x'), lat), 'lon': (('y', 'x'), lon), 'x': (('x', ), np.arange(5)), 'y': (('y', ), np.arange(4)), }) print(da.coords)
Coordinates:
- y (y) int64 0 1 2 3 lon (y, x) float64 -20.0 -10.0 0.0 10.0 20.0 -20.0 -10.0 0.0 10.0 ...
- x (x) int64 0 1 2 3 4 lat (y, x) float64 0.0 0.0 0.0 0.0 0.0 10.0 10.0 10.0 10.0 10.0 ...