17
17
import artist
18
18
from artist import Artist , allow_rasterization
19
19
from 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
21
21
from matplotlib import _image
22
22
import colorbar as cbar
23
23
from image import FigureImage
27
27
28
28
from legend import Legend
29
29
from 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
32
31
from matplotlib .blocking_input import BlockingMouseInput , BlockingKeyMouseInput
33
32
34
33
import matplotlib .cbook as cbook
35
34
from matplotlib import docstring
36
35
37
36
from operator import itemgetter
38
- import os . path
37
+
39
38
40
39
docstring .interpd .update (projection_names = get_projection_names ())
41
40
@@ -110,7 +109,8 @@ def add(self, key, a):
110
109
a_existing = self .get (key )
111
110
if a_existing is not None :
112
111
Stack .remove (self , (key , a_existing ))
113
- warnings .Warn (
112
+ import warnings
113
+ warnings .warn (
114
114
"key %s already existed; Axes is being replaced" % key )
115
115
# I don't think the above should ever happen.
116
116
@@ -138,6 +138,7 @@ def __call__(self):
138
138
def __contains__ (self , a ):
139
139
return a in self .as_list ()
140
140
141
+
141
142
class SubplotParams :
142
143
"""
143
144
8000
A class to hold the parameters for a subplot
@@ -212,8 +213,6 @@ def reset():
212
213
reset ()
213
214
raise ValueError ('bottom cannot be >= top' )
214
215
215
-
216
-
217
216
def _update_this (self , s , val ):
218
217
if val is None :
219
218
val = getattr (self , s , None )
@@ -223,6 +222,7 @@ def _update_this(self, s, val):
223
222
224
223
setattr (self , s , val )
225
224
225
+
226
226
class Figure (Artist ):
227
227
228
228
"""
@@ -1081,13 +1081,9 @@ def gca(self, **kwargs):
1081
1081
The following kwargs are supported for ensuring the returned axes
1082
1082
adheres to the given projection etc., and for axes creation if
1083
1083
the active axes does not exist:
1084
+
1084
1085
%(Axes)s
1085
1086
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
-
1091
1087
"""
1092
1088
ckey , cax = self ._axstack .current_key_axes ()
1093
1089
# if there exists an axes on the stack see if it maches
@@ -1107,12 +1103,18 @@ def gca(self, **kwargs):
1107
1103
kwargs_copy = kwargs .copy ()
1108
1104
projection_class , _ , key = \
1109
1105
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
+
1110
1111
# if the cax matches this key then return the axes, otherwise
1111
1112
# continue and a new axes will be created
1112
1113
if key == ckey and isinstance (cax , projection_class ):
1113
1114
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 )
1116
1118
1117
1119
def sca (self , a ):
1118
1120
'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
1395
1397
self .subplots_adjust (** kwargs )
1396
1398
1397
1399
1398
-
1399
1400
def figaspect (arg ):
1400
1401
"""
1401
1402
Create a figure with specified aspect ratio. If *arg* is a number,
0 commit comments