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..d0d38c78ed7f 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 + ln1, = plt.polar(0., 1., 'ro') + assert isinstance(ln1, mpl.lines.Line2D) + # the second call should reuse the existing 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