Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c6acfc

Browse files
committed
Fix polar() regression on second call failure
1 parent 70f2145 commit 6c6acfc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,14 +2193,12 @@ def polar(*args, **kwargs):
21932193
# If an axis already exists, check if it has a polar projection
21942194
if gcf().get_axes():
21952195
ax = gca()
2196-
if isinstance(ax, PolarAxes):
2197-
return ax
2198-
else:
2196+
if not isinstance(ax, PolarAxes):
21992197
_api.warn_external('Trying to create polar plot on an Axes '
22002198
'that does not have a polar projection.')
2201-
ax = axes(projection="polar")
2202-
ret = ax.plot(*args, **kwargs)
2203-
return ret
2199+
else:
2200+
ax = axes(projection="polar")
2201+
return ax.plot(*args, **kwargs)
22042202

22052203

22062204
# If rcParams['backend_fallback'] is true, and an interactive backend is

lib/matplotlib/tests/test_pyplot.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,13 @@ def test_subplot_change_projection():
310310
assert ax_next.name == proj
311311
assert ax is not ax_next
312312
ax = ax_next
313+
314+
315+
def test_polar_second_call():
316+
# the first call creates the axes with polar projection
317+
h1 = plt.polar(0., 1., 'ro')
318+
assert isinstance(h1[0], mpl.lines.Line2D)
319+
# the second call should reuse the existing axes
320+
h2 = plt.polar(1.57, .5, 'bo')
321+
assert isinstance(h2[0], mpl.lines.Line2D)
322+
assert h1[0].axes is h2[0].axes

0 commit comments

Comments
 (0)