1717import artist
1818from artist import Artist , allow_rasterization
1919from axes import Axes , SubplotBase , subplot_class_factory
20- from cbook import flatten , allequal , Stack , iterable , is_string_like
20+ from cbook import allequal , Stack , iterable
2121from matplotlib import _image
2222import colorbar as cbar
2323from image import FigureImage
2727
2828from legend import Legend
2929from transforms import Affine2D , Bbox , BboxTransformTo , TransformedBbox
30- from projections import get_projection_names , get_projection_class , \
31- process_projection_requirements
30+ from projections import get_projection_names , process_projection_requirements
3231from matplotlib .blocking_input import BlockingMouseInput , BlockingKeyMouseInput
3332
3433import matplotlib .cbook as cbook
3534from matplotlib import docstring
3635
3736from operator import itemgetter
38- import os . path
37+
3938
4039docstring .interpd .update (projection_names = get_projection_names ())
4140
@@ -110,7 +109,8 @@ def add(self, key, a):
110109 a_existing = self .get (key )
111110 if a_existing is not None :
112111 Stack .remove (self , (key , a_existing ))
113- warnings .Warn (
112+ import warnings
113+ warnings .warn (
114114 "key %s already existed; Axes is being replaced" % key )
115115 # I don't think the above should ever happen.
116116
@@ -138,6 +138,7 @@ def __call__(self):
138138 def __contains__ (self , a ):
139139 return a in self .as_list ()
140140
141+
141142class SubplotParams :
142143 """
143144 A class to hold the parameters for a subplot
@@ -212,8 +213,6 @@ def reset():
212213 reset ()
213214 raise ValueError ('bottom cannot be >= top' )
214215
215-
216-
217216 def _update_this (self , s , val ):
218217 if val is None :
219218 val = getattr (self , s , None )
@@ -223,6 +222,7 @@ def _update_this(self, s, val):
223222
224223 setattr (self , s , val )
225224
225+
226226class Figure (Artist ):
227227
228228 """
@@ -1077,13 +1077,9 @@ def gca(self, **kwargs):
10771077 The following kwargs are supported for ensuring the returned axes
10781078 adheres to the given projection etc., and for axes creation if
10791079 the active axes does not exist:
1080+
10801081 %(Axes)s
10811082
1082- .. note::
1083- When specifying kwargs to ``gca`` to find the pre-created active
1084- axes, they should be equivalent in every way to the kwargs which
1085- were used in its creation.
1086-
10871083 """
10881084 ckey , cax = self ._axstack .current_key_axes ()
10891085 # if there exists an axes on the stack see if it maches
@@ -1103,12 +1099,18 @@ def gca(self, **kwargs):
11031099 kwargs_copy = kwargs .copy ()
11041100 projection_class , _ , key = \
11051101 process_projection_requirements (self , ** kwargs_copy )
1102+
1103+ # let the returned axes have any gridspec by removing it from the key
1104+ ckey = ckey [1 :]
1105+ key = key [1 :]
1106+
11061107 # if the cax matches this key then return the axes, otherwise
11071108 # continue and a new axes will be created
11081109 if key == ckey and isinstance (cax , projection_class ):
11091110 return cax
1110-
1111- return self .add_subplot (111 , ** kwargs )
1111+
1112+ # no axes found, so create one which spans the figure
1113+ return self .add_subplot (1 , 1 , 1 , ** kwargs )
11121114
11131115 def sca (self , a ):
11141116 'Set the current axes to be a and return a'
@@ -1391,7 +1393,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=Non
13911393 self .subplots_adjust (** kwargs )
13921394
13931395
1394-
13951396def figaspect (arg ):
13961397 """
13971398 Create a figure with specified aspect ratio. If *arg* is a number,
0 commit comments