From 6c6acfc86716a3d420b3937317a0e7321059ed27 Mon Sep 17 00:00:00 2001 From: Jeff Beck Date: Sun, 19 Sep 2021 12:06:07 -0700 Subject: [PATCH 1/2] Fix polar() regression on second call failure --- lib/matplotlib/pyplot.py | 10 ++++------ lib/matplotlib/tests/test_pyplot.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index fc339eae3690..2578bf001353 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2193,14 +2193,12 @@ def polar(*args, **kwargs): # If an axis already exists, check if it has a polar projection if gcf().get_axes(): ax = gca() - if isinstance(ax, PolarAxes): - return ax - else: + if not isinstance(ax, PolarAxes): _api.warn_external('Trying to create polar plot on an Axes ' 'that does not have a polar projection.') - ax = axes(projection="polar") - ret = ax.plot(*args, **kwargs) - return ret + else: + ax = axes(projection="polar") + return ax.plot(*args, **kwargs) # If rcParams['backend_fallback'] is true, and an interactive backend is diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index c2c71d586715..b95f1ae40dc9 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -310,3 +310,13 @@ def test_subplot_change_projection(): assert ax_next.name == proj assert ax is not ax_next ax = ax_next + + +def test_polar_second_call(): + # the first call creates the axes with polar projection + h1 = plt.polar(0., 1., 'ro') + assert isinstance(h1[0], mpl.lines.Line2D) + # the second call should reuse the existing axes + h2 = plt.polar(1.57, .5, 'bo') + assert isinstance(h2[0], mpl.lines.Line2D) + assert h1[0].axes is h2[0].axes From 9ee9f3ef67b16be1a48d4bb12df673c902bc3625 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 19 Sep 2021 19:51:36 -0400 Subject: [PATCH 2/2] STY: tweak unpacking in polar test a bit --- lib/matplotlib/tests/test_pyplot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index b95f1ae40dc9..d0d38c78ed7f 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -314,9 +314,9 @@ def test_subplot_change_projection(): def test_polar_second_call(): # the first call creates the axes with polar projection - h1 = plt.polar(0., 1., 'ro') - assert isinstance(h1[0], mpl.lines.Line2D) + ln1, = plt.polar(0., 1., 'ro') + assert isinstance(ln1, mpl.lines.Line2D) # the second call should reuse the existing axes - h2 = plt.polar(1.57, .5, 'bo') - assert isinstance(h2[0], mpl.lines.Line2D) - assert h1[0].axes is h2[0].axes + ln2, = plt.polar(1.57, .5, 'bo') + assert isinstance(ln2, mpl.lines.Line2D) + assert ln1.axes is ln2.axes 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