(
darray: DataArray, x: Hashable | None, y: Hashable | None, hue: Hashable | None
)
| 62 | |
| 63 | |
| 64 | def _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 |
no test coverage detected
searching dependent graphs…