22
22
import matplotlib .artist as martist
23
23
import matplotlib .patches as mpatches
24
24
import matplotlib .path as mpath
25
+ import matplotlib .scale as mscale
25
26
import matplotlib .spines as mspines
26
27
import matplotlib .transforms as mtransforms
27
28
from matplotlib import docstring
@@ -237,28 +238,14 @@ def __init__(self, cbar):
237
238
self ._orig_locator = cbar .ax ._axes_locator
238
239
239
240
def __call__ (self , ax , renderer ):
240
-
241
- # make sure that lims and scales are the same
242
- if 0 :
243
- scale = self ._cbar ._long_axis ()._scale
244
- try :
245
- self ._cbar ._short_axis ()._set_scale (scale )
246
- except TypeError :
247
- pass
248
- lim = self ._cbar ._long_axis ().get_view_interval ()
249
- print ('lim' , lim , scale , self ._cbar .ax .get_xlim (), self ._cbar .ax .get_ylim (),
250
- self ._cbar .orientation )
251
- self ._cbar .ax .set_xlim (lim )
252
- self ._cbar .ax .set_ylim (lim )
253
-
254
-
241
+ print (ax == self ._cbar .ax )
242
+ print ('lim' ,self ._cbar .ax .get_xlim (), self ._cbar .ax .get_ylim (),
243
+ self ._cbar .orientation , self ._cbar .ax .yaxis ._scale )
255
244
if self ._orig_locator is not None :
256
245
pos = self ._orig_locator (ax , renderer )
257
246
else :
258
247
pos = ax .get_position (original = True )
259
248
if self ._cbar .extend == 'neither' :
260
- print ('pos0' , pos )
261
-
262
249
return pos
263
250
264
251
y , extendlen = self ._cbar ._proportional_y ()
@@ -277,17 +264,15 @@ def __call__(self, ax, renderer):
277
264
aspect = False
278
265
# now shrink and/or offset to take into account the
279
266
# extend tri/rectangles.
280
- print ('aspect' , aspect , shrink )
281
- print ('pos0' , pos )
282
267
if self ._cbar .orientation == 'vertical' :
283
268
if aspect :
284
- ax . set_box_aspect (aspect * shrink )
269
+ self . _cbar . set_aspect (aspect * shrink )
285
270
pos = pos .shrunk (1 , shrink ).translated (0 , offset * pos .height )
286
271
else :
272
+ self ._cbar .ax .set_ylim (0 , 1 )
287
273
if aspect :
288
- ax .set_box_aspect (aspect / shrink )
274
+ ax ._cbar . set_aspect (aspect * shrink )
289
275
pos = pos .shrunk (shrink , 1 ).translated (offset * pos .width , 0 )
290
- print ('pos' , pos )
291
276
return pos
292
277
293
278
def get_subplotspec (self ):
@@ -577,6 +562,7 @@ def draw_all(self):
577
562
if self ._extend_upper ():
578
563
ind = ind [:- 1 ]
579
564
self ._add_solids (X , Y , self ._values [ind , np .newaxis ])
565
+ print ('Done draw all' )
580
566
581
567
def _add_solids (self , X , Y , C ):
582
568
"""Draw the colors; optionally add separators."""
@@ -929,6 +915,59 @@ def set_alpha(self, alpha):
929
915
"""Set the transparency between 0 (transparent) and 1 (opaque)."""
930
916
self .alpha = alpha
931
917
918
+ def set_scale (self , scale , ** kwargs ):
919
+ """
920
+ Set the colorbar long axis scale.
921
+
922
+ Parameters
923
+ ----------
924
+ value : {"linear", "log", "symlog", "logit", ...} or `.ScaleBase`
925
+ The axis scale type to apply.
926
+
927
+ **kwargs
928
+ Different keyword arguments are accepted, depending on the scale.
929
+ See the respective class keyword arguments:
930
+
931
+ - `matplotlib.scale.LinearScale`
932
+ - `matplotlib.scale.LogScale`
933
+ - `matplotlib.scale.SymmetricalLogScale`
934
+ - `matplotlib.scale.LogitScale`
935
+ - `matplotlib.scale.FuncScale`
936
+
937
+ Notes
938
+ -----
939
+ By default, Matplotlib supports the above mentioned scales.
940
+ Additionally, custom scales may be registered using
941
+ `matplotlib.scale.register_scale`. These scales can then also
942
+ be used here.
943
+ """
944
+ if self .orientation == 'vertical' :
945
+ self .ax .set_yscale (scale , ** kwargs )
946
+ else :
947
+ self .ax .set_xscale (scale , ** kwargs )
948
+ if isinstance (scale , mscale .ScaleBase ):
949
+ self .__scale = scale .name
950
+ else :
951
+ self .__scale = scale
952
+
953
+ def get_scale (self ):
954
+ """
955
+ Return the colorbar's axis scale as a str.
956
+ """
957
+ if self .orientation == 'vertical' :
958
+ return self .ax .get_yscale ()
959
+ else :
960
+ return self .ax .get_xscale ()
961
+
962
+ def set_aspect (self , aspect ):
963
+ """
964
+ Set ratio of the long axis to short axis.
965
+ """
966
+ if self .orientation == 'horizontal' :
967
+ aspect = 1 / aspect
968
+ self .ax .set_box_aspect (aspect )
969
+ self .ax .set_aspect ('auto' )
970
+
932
971
def remove (self ):
933
972
"""
934
973
Remove this colorbar from the figure.
@@ -1075,44 +1114,38 @@ def _inverse_boundaries(self, x):
1075
1114
b = self ._boundaries
1076
1115
return np .interp (x , np .linspace (0 , b [- 1 ], len (b )), b )
1077
1116
1117
+
1078
1118
def _reset_locator_formatter_scale (self ):
1079
1119
"""
1080
1120
Reset the locator et al to defaults. Any user-hardcoded changes
1081
1121
need to be re-entered if this gets called (either at init, or when
1082
1122
the mappable normal gets changed: Colorbar.update_normal)
1083
1123
"""
1124
+ print ('Yee haw' , self .norm ._scale )
1125
+
1084
1126
self ._process_values ()
1085
1127
self .locator = None
1086
1128
self .minorlocator = None
1087
1129
self .formatter = None
1130
+ longax = self ._long_axis ()
1088
1131
if (self .boundaries is not None or
1089
1132
isinstance (self .norm , colors .BoundaryNorm )):
1090
1133
if self .spacing == 'uniform' :
1091
1134
funcs = (self ._forward_boundaries , self ._inverse_boundaries )
1092
- self .ax .set_xscale ('function' , functions = funcs )
1093
- self .ax .set_yscale ('function' , functions = funcs )
1094
- self .__scale = 'function'
1135
+ self .set_scale ('function' , functions = funcs )
1095
1136
elif self .spacing == 'proportional' :
1096
- self .__scale = 'linear'
1097
- self .ax .set_xscale ('linear' )
1098
- self .ax .set_yscale ('linear' )
1137
+ self .set_scale ('linear' )
1099
1138
elif hasattr (self .norm , '_scale' ) and self .norm ._scale is not None :
1100
1139
# use the norm's scale:
1101
- self .ax .set_xscale (self .norm ._scale )
1102
- self .ax .set_yscale (self .norm ._scale )
1103
- self .__scale = self .norm ._scale .name
1140
+ self .set_scale (self .norm ._scale )
1104
1141
elif type (self .norm ) is colors .Normalize :
1105
1142
# plain Normalize:
1106
- self .ax .set_xscale ('linear' )
1107
- self .ax .set_yscale ('linear' )
1108
- self .__scale = 'linear'
1143
+ self .set_scale ('linear' )
1109
1144
else :
1110
1145
# norm._scale is None or not an attr: derive the scale from
1111
1146
# the Norm:
1112
1147
funcs = (self .norm , self .norm .inverse )
1113
- self .ax .set_xscale ('function' , functions = funcs )
1114
- self .ax .set_yscale ('function' , functions = funcs )
1115
- self .__scale = 'function'
1148
+ self .set_scale ('function' , functions = funcs )
1116
1149
1117
1150
def _locate (self , x ):
1118
1151
"""
@@ -1350,7 +1383,9 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1350
1383
aspect = aspect ,
1351
1384
pad = pad )
1352
1385
# and we need to set the aspect ratio by hand...
1353
- cax .set_box_aspect (aspect , anchor = anchor )
1386
+ cax .set_anchor (anchor )
1387
+ cax .set_box_aspect (aspect )
1388
+ cax .set_aspect ('auto' )
1354
1389
1355
1390
return cax , kw
1356
1391
@@ -1451,7 +1486,9 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
1451
1486
1452
1487
fig = parent .get_figure ()
1453
1488
cax = fig .add_subplot (ss_cb , label = "<colorbar>" )
1454
- cax .set_box_aspect (aspect ,)
1489
+ cax .set_anchor (anchor )
1490
+ cax .set_box_aspect (aspect )
1491
+ cax .set_aspect ('auto' )
1455
1492
cax ._colorbar_info = dict (
1456
1493
location = location ,
1457
1494
parents = [parent ],
0 commit comments