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

Skip to content

Commit a889cff

Browse files
authored
Merge pull request #7604 from dstansby/polar-plots
Warn if different axis projection requested
2 parents a15d5c8 + 2aef993 commit a889cff

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,10 @@ def gca(self, **kwargs):
14851485
# continue and a new axes will be created
14861486
if key == ckey and isinstance(cax, projection_class):
14871487
return cax
1488+
else:
1489+
warnings.warn('Requested projection is different from '
1490+
'current axis projection, creating new axis '
1491+
'with requested projection.')
14881492

14891493
# no axes found, so create one which spans the figure
14901494
return self.add_subplot(1, 1, 1, **kwargs)

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,11 @@ def polar(*args, **kwargs):
22792279
strings, as in :func:`~matplotlib.pyplot.plot`.
22802280
22812281
"""
2282+
# If an axis already exists, check if it has a polar projection
2283+
if gcf().get_axes():
2284+
if not isinstance(gca(), PolarAxes):
2285+
warnings.warn('Trying to create polar plot on an axis that does '
2286+
'not have a polar projection.')
22822287
ax = gca(polar=True)
22832288
ret = ax.plot(*args, **kwargs)
22842289
return ret

0 commit comments

Comments
 (0)