@@ -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