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
@@ -256,8 +256,6 @@ class ColorbarBase(cm.ScalarMappable):
256
256
'min' : slice (1 , None ),
257
257
'max' : slice (0 , - 1 )}
258
258
259
- n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
260
-
261
259
def __init__ (self , ax , cmap = None ,
262
260
norm = None ,
263
261
alpha = None ,
@@ -311,13 +309,10 @@ def __init__(self, ax, cmap=None,
311
309
self .locator = ticks # Handle default in _ticker()
312
310
if format is None :
313
311
if isinstance (self .norm , colors .LogNorm ):
314
- self .formatter = ticker .LogFormatterSciNotation ()
315
- elif isinstance (self .norm , colors .SymLogNorm ):
316
- self .formatter = ticker .LogFormatterSciNotation (
317
- linthresh = self .norm .linthresh )
312
+ self .formatter = ticker .LogFormatterMathtext ()
318
313
else :
319
314
self .formatter = ticker .ScalarFormatter ()
320
- elif isinstance (format , six . string_types ):
315
+ elif cbook . is_string_like (format ):
321
316
self .formatter = ticker .FormatStrFormatter (format )
322
317
else :
323
318
self .formatter = format # Assume it is a Formatter
@@ -344,7 +339,6 @@ def draw_all(self):
344
339
Calculate any free parameters based on the current cmap and norm,
345
340
and do all the drawing.
346
341
'''
347
-
348
342
self ._process_values ()
349
343
self ._find_range ()
350
344
X , Y = self ._mesh ()
@@ -400,10 +394,6 @@ def set_ticks(self, ticks, update_ticks=True):
400
394
self .update_ticks ()
401
395
self .stale = True
402
396
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
397
def set_ticklabels (self , ticklabels , update_ticks = True ):
408
398
"""
409
399
set tick labels. Tick labels are updated immediately unless
@@ -509,10 +499,10 @@ def _add_solids(self, X, Y, C):
509
499
# Save, set, and restore hold state to keep pcolor from
510
500
# clearing the axes. Ordinarily this will not be needed,
511
501
# since the axes object should already have hold set.
512
- _hold = self .ax ._hold
513
- self .ax ._hold = True
502
+ _hold = self .ax .ishold ()
503
+ self .ax .hold ( True )
514
504
col = self .ax .pcolormesh (* args , ** kw )
515
- self .ax ._hold = _hold
505
+ self .ax .hold ( _hold )
516
506
#self.add_observer(col) # We should observe, not be observed...
517
507
518
508
if self .solids is not None :
@@ -527,8 +517,6 @@ def _add_solids(self, X, Y, C):
527
517
colors = (mpl .rcParams ['axes.edgecolor' ],),
528
518
linewidths = linewidths )
529
519
self .ax .add_collection (self .dividers )
530
- elif len (self ._y ) >= self .n_rasterize :
531
- self .solids .set_rasterized (True )
532
520
533
521
def add_lines (self , levels , colors , linewidths , erase = True ):
534
522
'''
@@ -582,23 +570,13 @@ def _ticker(self):
582
570
b = self .norm .boundaries
583
571
locator = ticker .FixedLocator (b , nbins = 10 )
584
572
elif isinstance (self .norm , colors .LogNorm ):
585
- locator = ticker .LogLocator (subs = 'all' )
586
- elif isinstance (self .norm , colors .SymLogNorm ):
587
- # The subs setting here should be replaced
588
- # by logic in the locator.
589
- locator = ticker .SymmetricalLogLocator (
590
- subs = np .arange (1 , 10 ),
591
- linthresh = self .norm .linthresh ,
592
- base = 10 )
573
+ locator = ticker .LogLocator ()
593
574
else :
594
- if mpl .rcParams ['_internal.classic_mode' ]:
595
- locator = ticker .MaxNLocator ()
596
- else :
597
- locator = ticker .AutoLocator ()
575
+ locator = ticker .MaxNLocator ()
598
576
else :
599
577
b = self ._boundaries [self ._inside ]
600
578
locator = ticker .FixedLocator (b , nbins = 10 )
601
- if isinstance (self .norm , colors .NoNorm ) and self . boundaries is None :
579
+ if isinstance (self .norm , colors .NoNorm ):
602
580
intv = self ._values [0 ], self ._values [- 1 ]
603
581
else :
604
582
intv = self .vmin , self .vmax
@@ -616,7 +594,6 @@ def _ticker(self):
616
594
else :
617
595
eps = (intv [1 ] - intv [0 ]) * 1e-10
618
596
b = b [(b <= intv [1 ] + eps ) & (b >= intv [0 ] - eps )]
619
- self ._tick_data_values = b
620
597
ticks = self ._locate (b )
621
598
formatter .set_locs (b )
622
599
ticklabels = [formatter (t , i ) for i , t in enumerate (b )]
@@ -687,24 +664,15 @@ def _process_values(self, b=None):
687
664
self .norm .vmin = 0
688
665
self .norm .vmax = 1
689
666
690
- self .norm .vmin , self .norm .vmax = mtransforms .nonsingular (
691
- self .norm .vmin ,
692
- self .norm .vmax ,
693
- expander = 0.1 )
667
+ self .norm .vmin , self .norm .vmax = mtrans .nonsingular (self .norm .vmin ,
668
+ self .norm .vmax ,
669
+ expander = 0.1 )
694
670
695
671
b = self .norm .inverse (self ._uniform_y (self .cmap .N + 1 ))
696
-
697
- if isinstance (self .norm , colors .LogNorm ):
698
- # If using a lognorm, ensure extensions don't go negative
699
- if self ._extend_lower ():
700
- b [0 ] = 0.9 * b [0 ]
701
- if self ._extend_upper ():
702
- b [- 1 ] = 1.1 * b [- 1 ]
703
- else :
704
- if self ._extend_lower ():
705
- b [0 ] = b [0 ] - 1
706
- if self ._extend_upper ():
707
- b [- 1 ] = b [- 1 ] + 1
672
+ if self ._extend_lower ():
673
+ b [0 ] = b [0 ] - 1
674
+ if self ._extend_upper ():
675
+ b [- 1 ] = b [- 1 ] + 1
708
676
self ._process_values (b )
709
677
710
678
def _find_range (self ):
@@ -1050,7 +1018,9 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1050
1018
shrink = 1.0 , aspect = 20 , ** kw ):
1051
1019
'''
1052
1020
Resize and reposition parent axes, and return a child
1053
- axes suitable for a colorbar.
1021
+ axes suitable for a colorbar::
1022
+
1023
+ cax, kw = make_axes(parent, **kw)
1054
1024
1055
1025
Keyword arguments may include the following (with defaults):
1056
1026
@@ -1117,18 +1087,18 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1117
1087
parent_anchor = kw .pop ('panchor' , loc_settings ['panchor' ])
1118
1088
pad = kw .pop ('pad' , loc_settings ['pad' ])
1119
1089
1120
- # turn parents into a list if it is not already
1121
- if not isinstance ( parents , ( list , tuple )):
1122
- parents = [ parents ]
1090
+ # turn parents into a list if it is not already. Using numpy because
1091
+ # `fig.subplots` returns an ndarray...
1092
+ parents = np . atleast_1d ( parents ). ravel (). tolist ()
1123
1093
1124
1094
fig = parents [0 ].get_figure ()
1125
1095
if not all (fig is ax .get_figure () for ax in parents ):
1126
1096
raise ValueError ('Unable to create a colorbar axes as not all '
1127
1097
'parents share the same figure.' )
1128
1098
1129
1099
# take a bounding box around all of the given axes
1130
- parents_bbox = mtransforms .Bbox .union (
1131
- [ ax . get_position ( original = True ). frozen () for ax in parents ])
1100
+ parents_bbox = mtrans .Bbox .union ([ ax . get_position ( original = True ). frozen ()
1101
+ for ax in parents ])
1132
1102
1133
1103
pb = parents_bbox
1134
1104
if location in ('left' , 'right' ):
@@ -1149,12 +1119,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1149
1119
1150
1120
# define a transform which takes us from old axes coordinates to
1151
1121
# new axes coordinates
1152
- shrinking_trans = mtransforms .BboxTransform (parents_bbox , pb1 )
1122
+ shrinking_trans = mtrans .BboxTransform (parents_bbox , pb1 )
1153
1123
1154
1124
# transform each of the axes in parents using the new transform
1155
1125
for ax in parents :
1156
1126
new_posn = shrinking_trans .transform (ax .get_position ())
1157
- new_posn = mtransforms .Bbox (new_posn )
1127
+ new_posn = mtrans .Bbox (new_posn )
1158
1128
ax .set_position (new_posn )
1159
1129
if parent_anchor is not False :
1160
1130
ax .set_anchor (parent_anchor )
@@ -1184,7 +1154,9 @@ def make_axes_gridspec(parent, **kw):
1184
1154
of the parent with a new one.
1185
1155
1186
1156
While this function is meant to be compatible with *make_axes*,
1187
- there could be some minor differences.
1157
+ there could be some minor differences.::
1158
+
1159
+ cax, kw = make_axes_gridspec(parent, **kw)
1188
1160
1189
1161
Keyword arguments may include the following (with defaults):
1190
1162
@@ -1287,8 +1259,8 @@ def _add_solids(self, X, Y, C):
1287
1259
# Save, set, and restore hold state to keep pcolor from
1288
1260
# clearing the axes. Ordinarily this will not be needed,
1289
1261
# since the axes object should already have hold set.
1290
- _hold = self .ax ._hold
1291
- self .ax ._hold = True
1262
+ _hold = self .ax .ishold ()
1263
+ self .ax .hold ( True )
1292
1264
1293
1265
kw = {'alpha' : self .alpha , }
1294
1266
@@ -1334,7 +1306,7 @@ def _add_solids(self, X, Y, C):
1334
1306
linewidths = (0.5 * mpl .rcParams ['axes.linewidth' ],))
1335
1307
self .ax .add_collection (self .dividers )
1336
1308
1337
- self .ax ._hold = _hold
1309
+ self .ax .hold ( _hold )
1338
1310
1339
1311
1340
1312
def colorbar_factory (cax , mappable , ** kwargs ):
0 commit comments