39
39
import matplotlib .patches as mpatches
40
40
import matplotlib .path as mpath
41
41
import matplotlib .ticker as ticker
42
- import matplotlib .transforms as mtransforms
42
+ import matplotlib .transforms as mtrans
43
43
44
44
from matplotlib import docstring
45
45
@@ -317,7 +317,7 @@ def __init__(self, ax, cmap=None,
317
317
linthresh = self .norm .linthresh )
318
318
else :
319
319
self .formatter = ticker .ScalarFormatter ()
320
- elif isinstance (format , six . string_types ):
320
+ elif cbook . is_string_like (format ):
321
321
self .formatter = ticker .FormatStrFormatter (format )
322
322
else :
323
323
self .formatter = format # Assume it is a Formatter
@@ -344,7 +344,6 @@ def draw_all(self):
344
344
Calculate any free parameters based on the current cmap and norm,
345
345
and do all the drawing.
346
346
'''
347
-
348
347
self ._process_values ()
349
348
self ._find_range ()
350
349
X , Y = self ._mesh ()
@@ -400,10 +399,6 @@ def set_ticks(self, ticks, update_ticks=True):
400
399
self .update_ticks ()
401
400
self .stale = True
402
401
403
- def get_ticks (self , minor = False ):
404
- """Return the x ticks as a list of locations"""
405
- return self ._tick_data_values
406
-
407
402
def set_ticklabels (self , ticklabels , update_ticks = True ):
408
403
"""
409
404
set tick labels. Tick labels are updated immediately unless
@@ -616,7 +611,6 @@ def _ticker(self):
616
611
else :
617
612
eps = (intv [1 ] - intv [0 ]) * 1e-10
618
613
b = b [(b <= intv [1 ] + eps ) & (b >= intv [0 ] - eps )]
619
- self ._tick_data_values = b
620
614
ticks = self ._locate (b )
621
615
formatter .set_locs (b )
622
616
ticklabels = [formatter (t , i ) for i , t in enumerate (b )]
@@ -687,10 +681,9 @@ def _process_values(self, b=None):
687
681
self .norm .vmin = 0
688
682
self .norm .vmax = 1
689
683
690
- self .norm .vmin , self .norm .vmax = mtransforms .nonsingular (
691
- self .norm .vmin ,
692
- self .norm .vmax ,
693
- expander = 0.1 )
684
+ self .norm .vmin , self .norm .vmax = mtrans .nonsingular (self .norm .vmin ,
685
+ self .norm .vmax ,
686
+ expander = 0.1 )
694
687
695
688
b = self .norm .inverse (self ._uniform_y (self .cmap .N + 1 ))
696
689
@@ -1117,19 +1110,17 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1117
1110
parent_anchor = kw .pop ('panchor' , loc_settings ['panchor' ])
1118
1111
pad = kw .pop ('pad' , loc_settings ['pad' ])
1119
1112
1120
- # turn parents into a list if it is not already. We do this w/ np
1121
- # because `plt.subplots` can return an ndarray and is natural to
1122
- # pass to `colorbar`.
1123
- parents = np .atleast_1d (parents ).ravel ()
1113
+ # turn parents into a list if it is not already
1114
+ parents = np .atleast_1d (parents ).ravel ().tolist ()
1124
1115
1125
1116
fig = parents [0 ].get_figure ()
1126
1117
if not all (fig is ax .get_figure () for ax in parents ):
1127
1118
raise ValueError ('Unable to create a colorbar axes as not all '
1128
1119
'parents share the same figure.' )
1129
1120
1130
1121
# take a bounding box around all of the given axes
1131
- parents_bbox = mtransforms .Bbox .union (
1132
- [ ax . get_position ( original = True ). frozen () for ax in parents ])
1122
+ parents_bbox = mtrans .Bbox .union ([ ax . get_position ( original = True ). frozen ()
1123
+ for ax in parents ])
1133
1124
1134
1125
pb = parents_bbox
1135
1126
if location in ('left' , 'right' ):
@@ -1150,12 +1141,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1150
1141
1151
1142
# define a transform which takes us from old axes coordinates to
1152
1143
# new axes coordinates
1153
- shrinking_trans = mtransforms .BboxTransform (parents_bbox , pb1 )
1144
+ shrinking_trans = mtrans .BboxTransform (parents_bbox , pb1 )
1154
1145
1155
1146
# transform each of the axes in parents using the new transform
1156
1147
for ax in parents :
1157
1148
new_posn = shrinking_trans .transform (ax .get_position ())
1158
- new_posn = mtransforms .Bbox (new_posn )
1149
+ new_posn = mtrans .Bbox (new_posn )
1159
1150
ax .set_position (new_posn )
1160
1151
if parent_anchor is not False :
1161
1152
ax .set_anchor (parent_anchor )
@@ -1166,7 +1157,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1166
1157
1167
1158
1168
1159
@docstring .Substitution (make_axes_kw_doc )
1169
- def make_axes_gridspec (parents , ** kw ):
1160
+ def make_axes_gridspec (parent , ** kw ):
1170
1161
'''
1171
1162
Resize and reposition a parent axes, and return a child axes
1172
1163
suitable for a colorbar. This function is similar to
@@ -1213,35 +1204,13 @@ def make_axes_gridspec(parents, **kw):
1213
1204
pad_s = (1. - shrink ) * 0.5
1214
1205
wh_ratios = [pad_s , shrink , pad_s ]
1215
1206
1216
- # make parents a 1-d ndarray if its not already...
1217
- parents = np .atleast_1d (parents ).ravel ()
1218
- # get the appropriate subplot spec. Loop through the parents.
1219
- gs0 = parents [0 ].get_subplotspec ().get_gridspec ()
1220
- minind = 10000
1221
- maxind = - 10000
1222
- for parent in parents :
1223
- gs = parent .get_subplotspec ().get_gridspec ()
1224
- if gs == gs0 :
1225
- ss = parent .get_subplotspec ().get_geometry ()
1226
- if ss [2 ]< minind :
1227
- minind = ss [2 ]
1228
- if ss [3 ]> maxind :
1229
- maxind = ss [3 ]
1230
- else :
1231
- pass
1232
- print (minind )
1233
- print (maxind )
1234
- subspec = gridspec .SubplotSpec (gs0 ,minind ,maxind )
1235
- print (subspec )
1236
- print (subspec .get_geometry ())
1237
-
1238
1207
gs_from_subplotspec = gridspec .GridSpecFromSubplotSpec
1239
1208
if orientation == 'vertical' :
1240
1209
pad = kw .pop ('pad' , 0.05 )
1241
1210
wh_space = 2 * pad / (1 - pad )
1242
1211
1243
1212
gs = gs_from_subplotspec (1 , 2 ,
1244
- subplot_spec = subspec ,
1213
+ subplot_spec = parent . get_subplotspec () ,
1245
1214
wspace = wh_space ,
1246
1215
width_ratios = [x1 - pad , fraction ]
1247
1216
)
@@ -1251,8 +1220,6 @@ def make_axes_gridspec(parents, **kw):
1251
1220
hspace = 0. ,
1252
1221
height_ratios = wh_ratios ,
1253
1222
)
1254
- print (gs )
1255
- print (gs2 )
1256
1223
1257
1224
anchor = (0.0 , 0.5 )
1258
1225
panchor = (1.0 , 0.5 )
@@ -1261,7 +1228,7 @@ def make_axes_gridspec(parents, **kw):
1261
1228
wh_space = 2 * pad / (1 - pad )
1262
1229
1263
1230
gs = gs_from_subplotspec (2 , 1 ,
1264
- subplot_spec = subspec ,
1231
+ subplot_spec = parent . get_subplotspec () ,
1265
1232
hspace = wh_space ,
1266
1233
height_ratios = [x1 - pad , fraction ]
1267
1234
)
@@ -1276,13 +1243,12 @@ def make_axes_gridspec(parents, **kw):
1276
1243
anchor = (0.5 , 1.0 )
1277
1244
panchor = (0.5 , 0.0 )
1278
1245
1279
- for parent in parents :
1280
- parent .set_subplotspec (gs [0 ])
1281
- parent .update_params ()
1282
- parent .set_position (parent .figbox )
1283
- parent .set_anchor (panchor )
1246
+ parent .set_subplotspec (gs [0 ])
1247
+ parent .update_params ()
1248
+ parent .set_position (parent .figbox )
1249
+ parent .set_anchor (panchor )
1284
1250
1285
- fig = parents [ 0 ] .get_figure ()
1251
+ fig = parent .get_figure ()
1286
1252
cax = fig .add_subplot (gs2 [1 ])
1287
1253
cax .set_aspect (aspect , anchor = anchor , adjustable = 'box' )
1288
1254
return cax , kw
0 commit comments