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 """
@@ -1081,13 +1081,9 @@ def gca(self, **kwargs):
10811081 The following kwargs are supported for ensuring the returned axes
10821082 adheres to the given projection etc., and for axes creation if
10831083 the active axes does not exist:
1084+
10841085 %(Axes)s
10851086
1086- .. note::
1087- When specifying kwargs to ``gca`` to find the pre-created active
1088- axes, they should be equivalent in every way to the kwargs which
1089- were used in its creation.
1090-
10911087 """
10921088 ckey , cax = self ._axstack .current_key_axes ()
10931089 # if there exists an axes on the stack see if it maches
@@ -1107,12 +1103,18 @@ def gca(self, **kwargs):
11071103 kwargs_copy = kwargs .copy ()
11081104 projection_class , _ , key = \
11091105 process_projection_requirements (self , ** kwargs_copy )
1106+
1107+ # let the returned axes have any gridspec by removing it from the key
1108+ ckey = ckey [1 :]
1109+ key = key [1 :]
1110+
11101111 # if the cax matches this key then return the axes, otherwise
11111112 # continue and a new axes will be created
11121113 if key == ckey and isinstance (cax , projection_class ):
11131114 return cax
1114-
1115- return self .add_subplot (111 , ** kwargs )
1115+
1116+ # no axes found, so create one which spans the figure
1117+ return self .add_subplot (1 , 1 , 1 , ** kwargs )
11161118
11171119 def sca (self , a ):
11181120 'Set the current axes to be a and return a'
@@ -1395,7 +1397,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=Non
13951397 self .subplots_adjust (** kwargs )
13961398
13971399
1398-
13991400def figaspect (arg ):
14001401 """
14011402 Create a figure with specified aspect ratio. If *arg* is a number,
0 commit comments