From 677bb49a6d0e8aab67740d39d1ec075aef543be0 Mon Sep 17 00:00:00 2001 From: nakamura yuki Date: Tue, 4 Jun 2024 14:59:39 +0000 Subject: [PATCH 01/12] add zorder option in QuiverKey modify indentation modify docstring add zorder test linting patch and small modify Add new api changes doc --- doc/api/next_api_changes/behavior/23116-YN.rst | 5 +++++ lib/matplotlib/quiver.py | 9 +++++++-- lib/matplotlib/tests/test_quiver.py | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 doc/api/next_api_changes/behavior/23116-YN.rst diff --git a/doc/api/next_api_changes/behavior/23116-YN.rst b/doc/api/next_api_changes/behavior/23116-YN.rst new file mode 100644 index 000000000000..edef4d4103e4 --- /dev/null +++ b/doc/api/next_api_changes/behavior/23116-YN.rst @@ -0,0 +1,5 @@ +Add zorder option in QuiverKey +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +It has been needed to use ``set_zorder`` when you set zorder in the QuiverKey. +This change can set zorder with ``zorder`` argument in the QuiverKey +in the same way as other plots. diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 240d7737b516..aea8654e4791 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -241,7 +241,8 @@ class QuiverKey(martist.Artist): def __init__(self, Q, X, Y, U, label, *, angle=0, coordinates='axes', color=None, labelsep=0.1, - labelpos='N', labelcolor=None, fontproperties=None, **kwargs): + labelpos='N', labelcolor=None, fontproperties=None, + zorder=None, **kwargs): """ Add a key to a quiver plot. @@ -285,6 +286,8 @@ def __init__(self, Q, X, Y, U, label, A dictionary with keyword arguments accepted by the `~matplotlib.font_manager.FontProperties` initializer: *family*, *style*, *variant*, *size*, *weight*. + zorder : float or None + The zorder of the key. The default is 0.1 above *Q*. **kwargs Any additional keyword arguments are used to override vector properties taken from *Q*. @@ -312,7 +315,9 @@ def __init__(self, Q, X, Y, U, label, if self.labelcolor is not None: self.text.set_color(self.labelcolor) self._dpi_at_last_init = None - self.zorder = Q.zorder + 0.1 + self.zorder = zorder + if self.zorder is None: + self.zorder = Q.zorder + 0.1 @property def labelsep(self): diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 7c5a9d343530..a542aba0aefe 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -6,6 +6,7 @@ from matplotlib import pyplot as plt from matplotlib.testing.decorators import image_comparison +from matplotlib.testing.decorators import check_figures_equal def draw_quiver(ax, **kwargs): @@ -333,3 +334,19 @@ def test_quiver_setuvc_numbers(): q = ax.quiver(X, Y, U, V) q.set_UVC(0, 1) + + +@check_figures_equal() +def test_zorder(fig_test, fig_ref): + """Check QuiverKey zorder option""" + X, Y, U, V = 1, 1, 2, 2 + + ax_test = fig_test.subplots() + zorder_value = 5. + q_test = ax_test.quiver(X, Y, U, V) + ax_test.quiverkey(q_test, 0.8, 0.3, U, label='U', zorder=zorder_value) + + ax_ref = fig_ref.subplots() + q_ref = ax_ref.quiver(X, Y, U, V) + qk_ref = ax_ref.quiverkey(q_ref, 0.8, 0.3, U, label='U') + qk_ref.set_zorder(zorder_value) From d54e66a00dfb0e675f3c86269a7e5ec6587caf02 Mon Sep 17 00:00:00 2001 From: nakamura yuki Date: Tue, 4 Jun 2024 15:01:50 +0000 Subject: [PATCH 02/12] add zorder option in QuiverKey --- 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 aea8654e4791..3e3a52fcabce 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -286,7 +286,7 @@ def __init__(self, Q, X, Y, U, label, A dictionary with keyword arguments accepted by the `~matplotlib.font_manager.FontProperties` initializer: *family*, *style*, *variant*, *size*, *weight*. - zorder : float or None + zorder : float, default: None The zorder of the key. The default is 0.1 above *Q*. **kwargs Any additional keyword arguments are used to override vector From 3a4d6121bceb27034852f0296cfe7702d7231a3a Mon Sep 17 00:00:00 2001 From: nakamura yuki Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 03/12] modify docstring add zorder test --- lib/matplotlib/quiver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 3e3a52fcabce..c48f29b5250c 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -287,6 +287,8 @@ def __init__(self, Q, X, Y, U, label, `~matplotlib.font_manager.FontProperties` initializer: *family*, *style*, *variant*, *size*, *weight*. zorder : float, default: None + zorder : float or None + zorder of the key. The zorder of the key. The default is 0.1 above *Q*. **kwargs Any additional keyword arguments are used to override vector From 39bbfbf52e8eddfb61a41cdf148875b31aa4050c Mon Sep 17 00:00:00 2001 From: nakamura yuki Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 04/12] linting patch and small modify --- lib/matplotlib/quiver.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index c48f29b5250c..6d53207a2078 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -288,7 +288,6 @@ def __init__(self, Q, X, Y, U, label, *family*, *style*, *variant*, *size*, *weight*. zorder : float, default: None zorder : float or None - zorder of the key. The zorder of the key. The default is 0.1 above *Q*. **kwargs Any additional keyword arguments are used to override vector From 0d7c12d42e20fb784931e6f334c0b0ae2dd9d51d Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 05/12] Update lib/matplotlib/tests/test_quiver.py Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/tests/test_quiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index a542aba0aefe..efc4dac06101 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -336,7 +336,7 @@ def test_quiver_setuvc_numbers(): q.set_UVC(0, 1) -@check_figures_equal() +@check_figures_equal(extensions=['png']) def test_zorder(fig_test, fig_ref): """Check QuiverKey zorder option""" X, Y, U, V = 1, 1, 2, 2 From 489786ba5a94fd5e2b9cdf74a841db30aee95ccf Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 06/12] add arg zorder --- lib/matplotlib/quiver.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/quiver.pyi b/lib/matplotlib/quiver.pyi index 2a043a92b4b5..460ad04637c0 100644 --- a/lib/matplotlib/quiver.pyi +++ b/lib/matplotlib/quiver.pyi @@ -45,6 +45,7 @@ class QuiverKey(martist.Artist): labelpos: Literal["N", "S", "E", "W"] = ..., labelcolor: ColorType | None = ..., fontproperties: dict[str, Any] | None = ..., + zorder: float, **kwargs ) -> None: ... @property From fe77ba7d0e87b52228a6122da7b2a8721e2b203e Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 07/12] revise stub --- lib/matplotlib/quiver.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/quiver.pyi b/lib/matplotlib/quiver.pyi index 460ad04637c0..515853ea3bb0 100644 --- a/lib/matplotlib/quiver.pyi +++ b/lib/matplotlib/quiver.pyi @@ -45,7 +45,7 @@ class QuiverKey(martist.Artist): labelpos: Literal["N", "S", "E", "W"] = ..., labelcolor: ColorType | None = ..., fontproperties: dict[str, Any] | None = ..., - zorder: float, + zorder: float | None = ..., **kwargs ) -> None: ... @property From 60fad74712b2c23209644db6413dc40ae4362c5b Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:03:17 +0000 Subject: [PATCH 08/12] add check quiverkey zorder tests --- lib/matplotlib/tests/test_quiver.py | 94 ++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index efc4dac06101..3207705a64b1 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -336,17 +336,91 @@ def test_quiver_setuvc_numbers(): q.set_UVC(0, 1) +def draw_quiverkey_zorder_argument(fig, zorder=None): + """Draw Quiver and QuiverKey with zorder argment""" + x = np.arange(1, 6, 1) + y = np.arange(1, 6, 1) + X, Y = np.meshgrid(x, y) + U, V = 2, 2 + + ax = fig.subplots() + q = ax.quiver(X, Y, U, V, pivot='middle') + ax.set_xlim(0.5, 5.5) + ax.set_ylim(0.5, 5.5) + if zorder is None: + ax.quiverkey(q, 4, 4, 25, + coordinates='data', label="U", color="blue") + ax.quiverkey(q, 5.5, 2, 20, + coordinates='data', label="V", color="blue", angle=90) + else: + ax.quiverkey(q, 4, 4, 25, + coordinates='data', label="U", color="blue", zorder=zorder) + ax.quiverkey(q, 5.5, 2, 20, + coordinates='data', label="V", color="blue", angle=90, zorder=zorder) + + +def draw_quiverkey_setzorder(fig, zorder=None): + """Draw Quiver and QuiverKey with set_zorder""" + x = np.arange(1, 6, 1) + y = np.arange(1, 6, 1) + X, Y = np.meshgrid(x, y) + U, V = 2, 2 + + ax = fig.subplots() + q = ax.quiver(X, Y, U, V, pivot='middle') + ax.set_xlim(0.5, 5.5) + ax.set_ylim(0.5, 5.5) + qk1 = ax.quiverkey(q, 4, 4, 25, + coordinates='data', label="U", color="blue") + qk2 = ax.quiverkey(q, 5.5, 2, 20, + coordinates='data', label="V", color="blue", angle=90) + if zorder is not None: + qk1.set_zorder(zorder) + qk2.set_zorder(zorder) + + @check_figures_equal(extensions=['png']) -def test_zorder(fig_test, fig_ref): +def test_quiverkey_zorder_default(fig_test, fig_ref): """Check QuiverKey zorder option""" - X, Y, U, V = 1, 1, 2, 2 + draw_quiverkey_zorder_argument(fig_test) + draw_quiverkey_setzorder(fig_ref) + + +@check_figures_equal(extensions=['png']) +def test_quiverkey_zorder_zero(fig_test, fig_ref): + """ + Check QuiverKey zorder option + zorder=0 means quiverkey is under quiver. + """ + draw_quiverkey_zorder_argument(fig_test, zorder=0) + draw_quiverkey_setzorder(fig_ref, zorder=0) + + +@check_figures_equal(extensions=['png']) +def test_quiverkey_zorder_two(fig_test, fig_ref): + """ + Check QuiverKey zorder option + zorder=2 means quiverkey is same as default. + """ + draw_quiverkey_zorder_argument(fig_test, zorder=2) + draw_quiverkey_setzorder(fig_ref, zorder=2) + + +@check_figures_equal(extensions=['png']) +def test_quiverkey_zorder_five(fig_test, fig_ref): + """ + Check QuiverKey zorder option + zorder=5 means quiverkey is over ticks. + """ + draw_quiverkey_zorder_argument(fig_test, zorder=5) + draw_quiverkey_setzorder(fig_ref, zorder=5) - ax_test = fig_test.subplots() - zorder_value = 5. - q_test = ax_test.quiver(X, Y, U, V) - ax_test.quiverkey(q_test, 0.8, 0.3, U, label='U', zorder=zorder_value) - ax_ref = fig_ref.subplots() - q_ref = ax_ref.quiver(X, Y, U, V) - qk_ref = ax_ref.quiverkey(q_ref, 0.8, 0.3, U, label='U') - qk_ref.set_zorder(zorder_value) +@check_figures_equal(extensions=['png']) +def test_quiverkey_zorder_None(fig_test, fig_ref): + """ + Check QuiverKey zorder option + zorder=None means quiverkey is over ticks. + """ + draw_quiverkey_zorder_argument(fig_test, zorder=None) + draw_quiverkey_setzorder(fig_ref, zorder=None) From 6d6da093aaec3a80f44d37e28015fbcbdb1f37ca Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:04:57 +0000 Subject: [PATCH 09/12] use single quote --- lib/matplotlib/tests/test_quiver.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 3207705a64b1..56b9c307b0ff 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -349,14 +349,14 @@ def draw_quiverkey_zorder_argument(fig, zorder=None): ax.set_ylim(0.5, 5.5) if zorder is None: ax.quiverkey(q, 4, 4, 25, - coordinates='data', label="U", color="blue") + coordinates='data', label='U', color='blue') ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label="V", color="blue", angle=90) + coordinates='data', label='V', color='blue', angle=90) else: ax.quiverkey(q, 4, 4, 25, - coordinates='data', label="U", color="blue", zorder=zorder) + coordinates='data', label='U', color='blue', zorder=zorder) ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label="V", color="blue", angle=90, zorder=zorder) + coordinates='data', label='V', color='blue', angle=90, zorder=zorder) def draw_quiverkey_setzorder(fig, zorder=None): @@ -371,9 +371,9 @@ def draw_quiverkey_setzorder(fig, zorder=None): ax.set_xlim(0.5, 5.5) ax.set_ylim(0.5, 5.5) qk1 = ax.quiverkey(q, 4, 4, 25, - coordinates='data', label="U", color="blue") + coordinates='data', label='U', color='blue') qk2 = ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label="V", color="blue", angle=90) + coordinates='data', label='V', color='blue', angle=90) if zorder is not None: qk1.set_zorder(zorder) qk2.set_zorder(zorder) From 79a15a74cf61b1f805749f5d84c16887990b46f6 Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:07:15 +0000 Subject: [PATCH 10/12] modify docstring --- lib/matplotlib/quiver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 6d53207a2078..46284ef8f89f 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -286,8 +286,7 @@ def __init__(self, Q, X, Y, U, label, A dictionary with keyword arguments accepted by the `~matplotlib.font_manager.FontProperties` initializer: *family*, *style*, *variant*, *size*, *weight*. - zorder : float, default: None - zorder : float or None + zorder : float The zorder of the key. The default is 0.1 above *Q*. **kwargs Any additional keyword arguments are used to override vector From c72803079d7c8ee54aab21de0b3d92024812d66b Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:11:07 +0000 Subject: [PATCH 11/12] flake8 check --- lib/matplotlib/tests/test_quiver.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 56b9c307b0ff..fda5a42846e5 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -348,15 +348,15 @@ def draw_quiverkey_zorder_argument(fig, zorder=None): ax.set_xlim(0.5, 5.5) ax.set_ylim(0.5, 5.5) if zorder is None: - ax.quiverkey(q, 4, 4, 25, - coordinates='data', label='U', color='blue') - ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label='V', color='blue', angle=90) + ax.quiverkey(q, 4, 4, 25, coordinates='data', + label='U', color='blue') + ax.quiverkey(q, 5.5, 2, 20, coordinates='data', + label='V', color='blue', angle=90) else: - ax.quiverkey(q, 4, 4, 25, - coordinates='data', label='U', color='blue', zorder=zorder) - ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label='V', color='blue', angle=90, zorder=zorder) + ax.quiverkey(q, 4, 4, 25, coordinates='data', + label='U', color='blue', zorder=zorder) + ax.quiverkey(q, 5.5, 2, 20, coordinates='data', + label='V', color='blue', angle=90, zorder=zorder) def draw_quiverkey_setzorder(fig, zorder=None): @@ -370,10 +370,10 @@ def draw_quiverkey_setzorder(fig, zorder=None): q = ax.quiver(X, Y, U, V, pivot='middle') ax.set_xlim(0.5, 5.5) ax.set_ylim(0.5, 5.5) - qk1 = ax.quiverkey(q, 4, 4, 25, - coordinates='data', label='U', color='blue') - qk2 = ax.quiverkey(q, 5.5, 2, 20, - coordinates='data', label='V', color='blue', angle=90) + qk1 = ax.quiverkey(q, 4, 4, 25, coordinates='data', + label='U', color='blue') + qk2 = ax.quiverkey(q, 5.5, 2, 20, coordinates='data', + label='V', color='blue', angle=90) if zorder is not None: qk1.set_zorder(zorder) qk2.set_zorder(zorder) From a7a4b55dc8546f1792636fe0bfc1ffb239baa4f8 Mon Sep 17 00:00:00 2001 From: muchojp <61620767+muchojp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:14:47 +0000 Subject: [PATCH 12/12] modify spell check --- lib/matplotlib/tests/test_quiver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index fda5a42846e5..06974a41afa3 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -337,7 +337,7 @@ def test_quiver_setuvc_numbers(): def draw_quiverkey_zorder_argument(fig, zorder=None): - """Draw Quiver and QuiverKey with zorder argment""" + """Draw Quiver and QuiverKey using zorder argument""" x = np.arange(1, 6, 1) y = np.arange(1, 6, 1) X, Y = np.meshgrid(x, y) @@ -360,7 +360,7 @@ def draw_quiverkey_zorder_argument(fig, zorder=None): def draw_quiverkey_setzorder(fig, zorder=None): - """Draw Quiver and QuiverKey with set_zorder""" + """Draw Quiver and QuiverKey using set_zorder""" x = np.arange(1, 6, 1) y = np.arange(1, 6, 1) X, Y = np.meshgrid(x, y) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy