|
72 | 72 | U, V : 1D or 2D array-like
|
73 | 73 | The x and y direction components of the arrow vectors.
|
74 | 74 |
|
| 75 | + They must have the same number of elements, matching the number of arrow |
| 76 | + locations. They may be masked. |
| 77 | +
|
75 | 78 | C : 1D or 2D array-like, optional
|
76 | 79 | Numeric data that defines the arrow colors by colormapping via *norm* and
|
77 | 80 | *cmap*.
|
78 | 81 |
|
79 | 82 | This does not support explicit colors. If you want to set colors directly,
|
80 |
| - use *color* instead. |
| 83 | + use *color* instead. The size of *C* must match the number of arrow |
| 84 | + locations. |
81 | 85 |
|
82 | 86 | units : {'width', 'height', 'dots', 'inches', 'x', 'y' 'xy'}, default: 'width'
|
83 | 87 | The arrow dimensions (except for *length*) are measured in multiples of
|
@@ -428,10 +432,13 @@ def _parse_args(*args, caller_name='function'):
|
428 | 432 | Y = Y.ravel()
|
429 | 433 | if len(X) == nc and len(Y) == nr:
|
430 | 434 | X, Y = [a.ravel() for a in np.meshgrid(X, Y)]
|
| 435 | + elif len(X) != len(Y): |
| 436 | + raise ValueError('X and Y must be the same size, but ' |
| 437 | + f'X.size is {X.size} and Y.size is {Y.size}.') |
431 | 438 | else:
|
432 | 439 | indexgrid = np.meshgrid(np.arange(nc), np.arange(nr))
|
433 | 440 | X, Y = [np.ravel(a) for a in indexgrid]
|
434 |
| - |
| 441 | + # Size validation for U, V, C is left to the set_UVC method. |
435 | 442 | return X, Y, U, V, C
|
436 | 443 |
|
437 | 444 |
|
@@ -589,9 +596,16 @@ def set_UVC(self, U, V, C=None):
|
589 | 596 | # to an array that might change before draw().
|
590 | 597 | U = ma.masked_invalid(U, copy=True).ravel()
|
591 | 598 | V = ma.masked_invalid(V, copy=True).ravel()
|
592 |
| - mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True) |
593 | 599 | if C is not None:
|
594 | 600 | C = ma.masked_invalid(C, copy=True).ravel()
|
| 601 | + for name, var in zip(('U', 'V', 'C'), (U, V, C)): |
| 602 | + if var is not None and var.size != self.N: |
| 603 | + raise ValueError(f'Argument {name} has a size {var.size}' |
| 604 | + f' which does not match {self.N},' |
| 605 | + ' the number of arrow positions') |
| 606 | + |
| 607 | + mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True) |
| 608 | + if C is not None: |
595 | 609 | mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
|
596 | 610 | if mask is ma.nomask:
|
597 | 611 | C = C.filled()
|
|
0 commit comments