MCPcopy
hub / github.com/pydata/xarray / _infer_xy_labels

Function _infer_xy_labels

xarray/plot/utils.py:394–431  ·  view source on GitHub ↗

Determine x and y labels. For use in _plot2d darray must be a 2 dimensional data array, or 3d for imshow only.

(
    darray: DataArray | Dataset,
    x: Hashable | None,
    y: Hashable | None,
    imshow: bool = False,
    rgb: Hashable | None = None,
)

Source from the content-addressed store, hash-verified

392
393
394def _infer_xy_labels(
395 darray: DataArray | Dataset,
396 x: Hashable | None,
397 y: Hashable | None,
398 imshow: bool = False,
399 rgb: Hashable | None = None,
400) -> tuple[Hashable, Hashable]:
401 """
402 Determine x and y labels. For use in _plot2d
403
404 darray must be a 2 dimensional data array, or 3d for imshow only.
405 """
406 if (x is not None) and (x == y):
407 raise ValueError("x and y cannot be equal.")
408
409 if imshow and darray.ndim == 3:
410 return _infer_xy_labels_3d(darray, x, y, rgb)
411
412 if x is None and y is None:
413 if darray.ndim != 2:
414 raise ValueError("DataArray must be 2d")
415 y, x = darray.dims
416 elif x is None:
417 _assert_valid_xy(darray, y, "y")
418 x = darray.dims[0] if y == darray.dims[1] else darray.dims[1]
419 elif y is None:
420 _assert_valid_xy(darray, x, "x")
421 y = darray.dims[0] if x == darray.dims[1] else darray.dims[1]
422 else:
423 _assert_valid_xy(darray, x, "x")
424 _assert_valid_xy(darray, y, "y")
425
426 if darray._indexes.get(x, 1) is darray._indexes.get(y, 2) and isinstance(
427 darray._indexes[x], PandasMultiIndex
428 ):
429 raise ValueError("x and y cannot be levels of the same MultiIndex")
430
431 return x, y
432
433
434# TODO: Can by used to more than x or y, rename?

Callers 4

_infer_line_dataFunction · 0.90
newplotfuncFunction · 0.90
map_dataarrayMethod · 0.90
_infer_xy_labels_3dFunction · 0.85

Calls 3

_infer_xy_labels_3dFunction · 0.85
_assert_valid_xyFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…