(ds, x, y, hue, hue_style, add_guide, funcname)
| 1225 | |
| 1226 | |
| 1227 | def _infer_meta_data(ds, x, y, hue, hue_style, add_guide, funcname): |
| 1228 | dvars = set(ds.variables.keys()) |
| 1229 | error_msg = f" must be one of ({', '.join(sorted(str(v) for v in dvars))})" |
| 1230 | |
| 1231 | if x not in dvars: |
| 1232 | raise ValueError(f"Expected 'x' {error_msg}. Received {x} instead.") |
| 1233 | |
| 1234 | if y not in dvars: |
| 1235 | raise ValueError(f"Expected 'y' {error_msg}. Received {y} instead.") |
| 1236 | |
| 1237 | if hue is not None and hue not in dvars: |
| 1238 | raise ValueError(f"Expected 'hue' {error_msg}. Received {hue} instead.") |
| 1239 | |
| 1240 | if hue: |
| 1241 | hue_is_numeric = _is_numeric(ds[hue].values) |
| 1242 | |
| 1243 | if hue_style is None: |
| 1244 | hue_style = "continuous" if hue_is_numeric else "discrete" |
| 1245 | |
| 1246 | if not hue_is_numeric and (hue_style == "continuous"): |
| 1247 | raise ValueError( |
| 1248 | f"Cannot create a colorbar for a non numeric coordinate: {hue}" |
| 1249 | ) |
| 1250 | |
| 1251 | if add_guide is None or add_guide is True: |
| 1252 | add_colorbar = hue_style == "continuous" |
| 1253 | add_legend = hue_style == "discrete" |
| 1254 | else: |
| 1255 | add_colorbar = False |
| 1256 | add_legend = False |
| 1257 | else: |
| 1258 | if add_guide is True and funcname not in ("quiver", "streamplot"): |
| 1259 | raise ValueError("Cannot set add_guide when hue is None.") |
| 1260 | add_legend = False |
| 1261 | add_colorbar = False |
| 1262 | |
| 1263 | if (add_guide or add_guide is None) and funcname == "quiver": |
| 1264 | add_quiverkey = True |
| 1265 | if hue: |
| 1266 | add_colorbar = True |
| 1267 | if not hue_style: |
| 1268 | hue_style = "continuous" |
| 1269 | elif hue_style != "continuous": |
| 1270 | raise ValueError( |
| 1271 | "hue_style must be 'continuous' or None for .plot.quiver or " |
| 1272 | ".plot.streamplot" |
| 1273 | ) |
| 1274 | else: |
| 1275 | add_quiverkey = False |
| 1276 | |
| 1277 | if (add_guide or add_guide is None) and funcname == "streamplot" and hue: |
| 1278 | add_colorbar = True |
| 1279 | if not hue_style: |
| 1280 | hue_style = "continuous" |
| 1281 | elif hue_style != "continuous": |
| 1282 | raise ValueError( |
| 1283 | "hue_style must be 'continuous' or None for .plot.quiver or " |
| 1284 | ".plot.streamplot" |
searching dependent graphs…