File tree 2 files changed +14
-6
lines changed
2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -2206,14 +2206,12 @@ def polar(*args, **kwargs):
2206
2206
# If an axis already exists, check if it has a polar projection
2207
2207
if gcf ().get_axes ():
2208
2208
ax = gca ()
2209
- if isinstance (ax , PolarAxes ):
2210
- return ax
2211
- else :
2209
+ if not isinstance (ax , PolarAxes ):
2212
2210
_api .warn_external ('Trying to create polar plot on an Axes '
2213
2211
'that does not have a polar projection.' )
2214
- ax = axes ( projection = "polar" )
2215
- ret = ax . plot ( * args , ** kwargs )
2216
- return ret
2212
+ else :
2213
+ ax = axes ( projection = "polar" )
2214
+ return ax . plot ( * args , ** kwargs )
2217
2215
2218
2216
2219
2217
# If rcParams['backend_fallback'] is true, and an interactive backend is
Original file line number Diff line number Diff line change @@ -310,3 +310,13 @@ def test_subplot_change_projection():
310
310
assert ax_next .name == proj
311
311
assert ax is not ax_next
312
312
ax = ax_next
313
+
314
+
315
+ def test_polar_second_call ():
316
+ # the first call creates the axes with polar projection
317
+ ln1 , = plt .polar (0. , 1. , 'ro' )
318
+ assert isinstance (ln1 , mpl .lines .Line2D )
319
+ # the second call should reuse the existing axes
320
+ ln2 , = plt .polar (1.57 , .5 , 'bo' )
321
+ assert isinstance (ln2 , mpl .lines .Line2D )
322
+ assert ln1 .axes is ln2 .axes
You can’t perform that action at this time.
0 commit comments