From a547f0d86dfbeb4cf52ad226863b144d5dfeac33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20N=C3=B6the?= Date: Thu, 12 Mar 2020 12:17:24 +0100 Subject: [PATCH 1/2] Allow numbers to set uvc for all arrows in quiver.set_UVC, fixes #16743 --- lib/matplotlib/quiver.py | 2 +- lib/matplotlib/tests/test_quiver.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 8f2ad56f0260..ac652a87bdf6 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -585,7 +585,7 @@ def set_UVC(self, U, V, C=None): if C is not None: C = ma.masked_invalid(C, copy=True).ravel() for name, var in zip(('U', 'V', 'C'), (U, V, C)): - if var is not None and var.size != self.N: + if var is not None and var.size != self.N and var.size != 1: raise ValueError(f'Argument {name} has a size {var.size}' f' which does not match {self.N},' ' the number of arrow positions') diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 8a6e0975e495..740ad3603a9c 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -247,3 +247,15 @@ def test_quiverkey_angles(): # The arrows are only created when the key is drawn fig.canvas.draw() assert len(qk.verts) == 1 + + +def test_quiver_setuvc_numbers(): + """Check that it is possible to set all arrow UVC to the same numbers""" + + fig, ax = plt.subplots() + + X, Y = np.meshgrid(np.arange(2), np.arange(2)) + U = V = np.ones_like(X) + + q = ax.quiver(X, Y, U, V) + q.set_UVC(0, 1) From a997baa07b6b9fb8904c51a400fce24df548bf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20N=C3=B6the?= Date: Thu, 12 Mar 2020 18:29:45 +0100 Subject: [PATCH 2/2] Improve readability of quiver dim check --- lib/matplotlib/quiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index ac652a87bdf6..91127b296896 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -585,7 +585,7 @@ def set_UVC(self, U, V, C=None): if C is not None: C = ma.masked_invalid(C, copy=True).ravel() for name, var in zip(('U', 'V', 'C'), (U, V, C)): - if var is not None and var.size != self.N and var.size != 1: + if not (var is None or var.size == self.N or var.size == 1): raise ValueError(f'Argument {name} has a size {var.size}' f' which does not match {self.N},' ' the number of arrow positions')