MCPcopy Index your code
hub / github.com/pydata/xarray / _infer_line_data

Function _infer_line_data

xarray/plot/dataarray_plot.py:64–145  ·  view source on GitHub ↗
(
    darray: DataArray, x: Hashable | None, y: Hashable | None, hue: Hashable | None
)

Source from the content-addressed store, hash-verified

62
63
64def _infer_line_data(
65 darray: DataArray, x: Hashable | None, y: Hashable | None, hue: Hashable | None
66) -> tuple[DataArray, DataArray, DataArray | None, str]:
67 ndims = len(darray.dims)
68
69 if x is not None and y is not None:
70 raise ValueError("Cannot specify both x and y kwargs for line plots.")
71
72 if x is not None:
73 _assert_valid_xy(darray, x, "x")
74
75 if y is not None:
76 _assert_valid_xy(darray, y, "y")
77
78 if ndims == 1:
79 huename = None
80 hueplt = None
81 huelabel = ""
82
83 if x is not None:
84 xplt = darray[x]
85 yplt = darray
86
87 elif y is not None:
88 xplt = darray
89 yplt = darray[y]
90
91 else: # Both x & y are None
92 dim = darray.dims[0]
93 xplt = darray[dim]
94 yplt = darray
95
96 else:
97 if x is None and y is None and hue is None:
98 raise ValueError("For 2D inputs, please specify either hue, x or y.")
99
100 if y is None:
101 if hue is not None:
102 _assert_valid_xy(darray, hue, "hue")
103 xname, huename = _infer_xy_labels(darray=darray, x=x, y=hue)
104 xplt = darray[xname]
105 if xplt.ndim > 1:
106 if huename in darray.dims:
107 otherindex = 1 if darray.dims.index(huename) == 0 else 0
108 otherdim = darray.dims[otherindex]
109 yplt = darray.transpose(otherdim, huename, transpose_coords=False)
110 xplt = xplt.transpose(otherdim, huename, transpose_coords=False)
111 else:
112 raise ValueError(
113 "For 2D inputs, hue must be a dimension"
114 " i.e. one of " + repr(darray.dims)
115 )
116
117 else:
118 (xdim,) = darray[xname].dims
119 (huedim,) = darray[huename].dims
120 yplt = darray.transpose(xdim, huedim)
121

Callers 2

map_dataarray_lineMethod · 0.90
lineFunction · 0.85

Calls 5

_assert_valid_xyFunction · 0.90
_infer_xy_labelsFunction · 0.90
label_from_attrsFunction · 0.90
indexMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…