Helper function to parse positional parameters for colored vector plots. This is currently used for Quiver and Barbs. Parameters ---------- *args : list list of 2-5 arguments. Depending on their number they are parsed to:: U, V U, V, C
(*args, caller_name='function')
| 439 | |
| 440 | |
| 441 | def _parse_args(*args, caller_name='function'): |
| 442 | """ |
| 443 | Helper function to parse positional parameters for colored vector plots. |
| 444 | |
| 445 | This is currently used for Quiver and Barbs. |
| 446 | |
| 447 | Parameters |
| 448 | ---------- |
| 449 | *args : list |
| 450 | list of 2-5 arguments. Depending on their number they are parsed to:: |
| 451 | |
| 452 | U, V |
| 453 | U, V, C |
| 454 | X, Y, U, V |
| 455 | X, Y, U, V, C |
| 456 | |
| 457 | caller_name : str |
| 458 | Name of the calling method (used in error messages). |
| 459 | """ |
| 460 | X = Y = C = None |
| 461 | |
| 462 | nargs = len(args) |
| 463 | if nargs == 2: |
| 464 | # The use of atleast_1d allows for handling scalar arguments while also |
| 465 | # keeping masked arrays |
| 466 | U, V = np.atleast_1d(*args) |
| 467 | elif nargs == 3: |
| 468 | U, V, C = np.atleast_1d(*args) |
| 469 | elif nargs == 4: |
| 470 | X, Y, U, V = np.atleast_1d(*args) |
| 471 | elif nargs == 5: |
| 472 | X, Y, U, V, C = np.atleast_1d(*args) |
| 473 | else: |
| 474 | raise _api.nargs_error(caller_name, takes="from 2 to 5", given=nargs) |
| 475 | |
| 476 | nr, nc = (1, U.shape[0]) if U.ndim == 1 else U.shape |
| 477 | |
| 478 | if X is not None: |
| 479 | X = X.ravel() |
| 480 | Y = Y.ravel() |
| 481 | if len(X) == nc and len(Y) == nr: |
| 482 | X, Y = (a.ravel() for a in np.meshgrid(X, Y)) |
| 483 | elif len(X) != len(Y): |
| 484 | raise ValueError('X and Y must be the same size, but ' |
| 485 | f'X.size is {X.size} and Y.size is {Y.size}.') |
| 486 | else: |
| 487 | indexgrid = np.meshgrid(np.arange(nc), np.arange(nr)) |
| 488 | X, Y = (np.ravel(a) for a in indexgrid) |
| 489 | # Size validation for U, V, C is left to the set_UVC method. |
| 490 | return X, Y, U, V, C |
| 491 | |
| 492 | |
| 493 | def _check_consistent_shapes(*arrays): |