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

Skip to content

Commit a4fc06b

Browse files
committed
Replace axes when current one is of the wrong projection type. This lets "subplot(111); polar()" work.
svn path=/trunk/matplotlib/; revision=6476
1 parent c61b019 commit a4fc06b

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

lib/matplotlib/figure.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,7 @@ def add_subplot(self, *args, **kwargs):
656656
%(Axes)s
657657
"""
658658

659-
key = self._make_key(*args, **kwargs)
660-
if key in self._seen:
661-
ax = self._seen[key]
662-
self.sca(ax)
663-
return ax
664-
659+
kwargs = kwargs.copy()
665660

666661
if not len(args): return
667662

@@ -680,8 +675,18 @@ def add_subplot(self, *args, **kwargs):
680675
projection = 'polar'
681676

682677
projection_class = get_projection_class(projection)
683-
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
684678

679+
key = self._make_key(*args, **kwargs)
680+
if key in self._seen:
681+
ax = self._seen[key]
682+
if isinstance(ax, projection_class):
683+
self.sca(ax)
684+
return ax
685+
else:
686+
self.axes.remove(ax)
687+
self._axstack.remove(ax)
688+
689+
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
685690
self.axes.append(a)
686691
self._axstack.push(a)
687692
self.sca(a)
@@ -891,7 +896,20 @@ def gca(self, **kwargs):
891896
%(Axes)s
892897
"""
893898
ax = self._axstack()
894-
if ax is not None: return ax
899+
if ax is not None:
900+
ispolar = kwargs.get('polar', False)
901+
projection = kwargs.get('projection', None)
902+
if ispolar:
903+
if projection is not None and projection != 'polar':
904+
raise ValueError(
905+
"polar=True, yet projection='%s'. " +
906+
"Only one of these arguments should be supplied." %
907+
projection)
908+
projection = 'polar'
909+
910+
projection_class = get_projection_class(projection)
911+
if isinstance(ax, projection_class):
912+
return ax
895913
return self.add_subplot(111, **kwargs)
896914
gca.__doc__ = dedent(gca.__doc__) % artist.kwdocd
897915

0 commit comments

Comments
 (0)