Warn if different axis projection requested #7604

Merged
merged 2 commits into from Dec 19, 2016
View
@@ -1485,6 +1485,10 @@ def gca(self, **kwargs):
# continue and a new axes will be created
if key == ckey and isinstance(cax, projection_class):
return cax
+ else:
+ warnings.warn('Requested projection is different from '
+ 'current axis projection, creating new axis '
+ 'with requested projection.')
# no axes found, so create one which spans the figure
return self.add_subplot(1, 1, 1, **kwargs)
View
@@ -2279,6 +2279,11 @@ def polar(*args, **kwargs):
strings, as in :func:`~matplotlib.pyplot.plot`.
"""
+ # If an axis already exists, check if it has a polar projection
+ if gcf().get_axes():
+ if not isinstance(gca(), PolarAxes):
+ warnings.warn('Trying to create polar plot on an axis that does '
+ 'not have a polar projection.')
ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
return ret