@@ -430,44 +430,51 @@ def __init__(self, ax, mappable=None, *, cmap=None,
430
430
self ._extend_cid2 = self .ax .callbacks .connect (
431
431
"ylim_changed" , self ._do_extends )
432
432
433
+ @property
434
+ def long_axis (self ):
435
+ """Axis that has decorations (ticks, etc) on it."""
436
+ if self .orientation == 'vertical' :
437
+ return self .ax .yaxis
438
+ return self .ax .xaxis
439
+
433
440
@property
434
441
def locator (self ):
435
442
"""Major tick `.Locator` for the colorbar."""
436
- return self ._long_axis () .get_major_locator ()
443
+ return self .long_axis .get_major_locator ()
437
444
438
445
@locator .setter
439
446
def locator (self , loc ):
440
- self ._long_axis () .set_major_locator (loc )
447
+ self .long_axis .set_major_locator (loc )
441
448
self ._locator = loc
442
449
443
450
@property
444
451
def minorlocator (self ):
445
452
"""Minor tick `.Locator` for the colorbar."""
446
- return self ._long_axis () .get_minor_locator ()
453
+ return self .long_axis .get_minor_locator ()
447
454
448
455
@minorlocator .setter
449
456
def minorlocator (self , loc ):
450
- self ._long_axis () .set_minor_locator (loc )
457
+ self .long_axis .set_minor_locator (loc )
451
458
self ._minorlocator = loc
452
459
453
460
@property
454
461
def formatter (self ):
455
462
"""Major tick label `.Formatter` for the colorbar."""
456
- return self ._long_axis () .get_major_formatter ()
463
+ return self .long_axis .get_major_formatter ()
457
464
458
465
@formatter .setter
459
466
def formatter (self , fmt ):
460
- self ._long_axis () .set_major_formatter (fmt )
467
+ self .long_axis .set_major_formatter (fmt )
461
468
self ._formatter = fmt
462
469
463
470
@property
464
471
def minorformatter (self ):
465
472
"""Minor tick `.Formatter` for the colorbar."""
466
- return self ._long_axis () .get_minor_formatter ()
473
+ return self .long_axis .get_minor_formatter ()
467
474
468
475
@minorformatter .setter
469
476
def minorformatter (self , fmt ):
470
- self ._long_axis () .set_minor_formatter (fmt )
477
+ self .long_axis .set_minor_formatter (fmt )
471
478
self ._minorformatter = fmt
472
479
473
480
def _cbar_cla (self ):
@@ -526,7 +533,7 @@ def _draw_all(self):
526
533
else :
527
534
if mpl .rcParams ['xtick.minor.visible' ]:
528
535
self .minorticks_on ()
529
- self ._long_axis () .set (label_position = self .ticklocation ,
536
+ self .long_axis .set (label_position = self .ticklocation ,
530
537
ticks_position = self .ticklocation )
531
538
self ._short_axis ().set_ticks ([])
532
539
self ._short_axis ().set_ticks ([], minor = True )
@@ -545,7 +552,7 @@ def _draw_all(self):
545
552
# also adds the outline path to self.outline spine:
546
553
self ._do_extends ()
547
554
lower , upper = self .vmin , self .vmax
548
- if self ._long_axis () .get_inverted ():
555
+ if self .long_axis .get_inverted ():
549
556
# If the axis is inverted, we need to swap the vmin/vmax
550
557
lower , upper = upper , lower
551
558
if self .orientation == 'vertical' :
@@ -686,7 +693,7 @@ def _do_extends(self, ax=None):
686
693
if self .orientation == 'horizontal' :
687
694
xy = xy [:, ::- 1 ]
688
695
# add the patch
689
- val = - 1 if self ._long_axis () .get_inverted () else 0
696
+ val = - 1 if self .long_axis .get_inverted () else 0
690
697
color = self .cmap (self .norm (self ._values [val ]))
691
698
patch = mpatches .PathPatch (
692
699
mpath .Path (xy ), facecolor = color , alpha = self .alpha ,
@@ -710,7 +717,7 @@ def _do_extends(self, ax=None):
710
717
if self .orientation == 'horizontal' :
711
718
xy = xy [:, ::- 1 ]
712
719
# add the patch
713
- val = 0 if self ._long_axis () .get_inverted () else - 1
720
+ val = 0 if self .long_axis .get_inverted () else - 1
714
721
color = self .cmap (self .norm (self ._values [val ]))
715
722
hatch_idx = len (self ._y ) - 1
716
723
patch = mpatches .PathPatch (
@@ -812,9 +819,9 @@ def update_ticks(self):
812
819
"""
813
820
# Get the locator and formatter; defaults to self._locator if not None.
814
821
self ._get_ticker_locator_formatter ()
815
- self ._long_axis () .set_major_locator (self ._locator )
816
- self ._long_axis () .set_minor_locator (self ._minorlocator )
817
- self ._long_axis () .set_major_formatter (self ._formatter )
822
+ self .long_axis .set_major_locator (self ._locator )
823
+ self .long_axis .set_minor_locator (self ._minorlocator )
824
+ self .long_axis .set_major_formatter (self ._formatter )
818
825
819
826
def _get_ticker_locator_formatter (self ):
820
827
"""
@@ -849,15 +856,15 @@ def _get_ticker_locator_formatter(self):
849
856
if locator is None :
850
857
# we haven't set the locator explicitly, so use the default
851
858
# for this axis:
852
- locator = self ._long_axis () .get_major_locator ()
859
+ locator = self .long_axis .get_major_locator ()
853
860
if minorlocator is None :
854
- minorlocator = self ._long_axis () .get_minor_locator ()
861
+ minorlocator = self .long_axis .get_minor_locator ()
855
862
856
863
if minorlocator is None :
857
864
minorlocator = ticker .NullLocator ()
858
865
859
866
if formatter is None :
860
- formatter = self ._long_axis () .get_major_formatter ()
867
+ formatter = self .long_axis .get_major_formatter ()
861
868
862
869
self ._locator = locator
863
870
self ._formatter = formatter
@@ -881,12 +888,12 @@ def set_ticks(self, ticks, *, labels=None, minor=False, **kwargs):
881
888
pass *labels*. In other cases, please use `~.Axes.tick_params`.
882
889
"""
883
890
if np .iterable (ticks ):
884
- self ._long_axis () .set_ticks (ticks , labels = labels , minor = minor ,
891
+ self .long_axis .set_ticks (ticks , labels = labels , minor = minor ,
885
892
** kwargs )
886
- self ._locator = self ._long_axis () .get_major_locator ()
893
+ self ._locator = self .long_axis .get_major_locator ()
887
894
else :
888
895
self ._locator = ticks
889
- self ._long_axis () .set_major_locator (self ._locator )
896
+ self .long_axis .set_major_locator (self ._locator )
890
897
self .stale = True
891
898
892
899
def get_ticks (self , minor = False ):
@@ -899,9 +906,9 @@ def get_ticks(self, minor=False):
899
906
if True return the minor ticks.
900
907
"""
901
908
if minor :
902
- return self ._long_axis () .get_minorticklocs ()
909
+ return self .long_axis .get_minorticklocs ()
903
910
else :
904
- return self ._long_axis () .get_majorticklocs ()
911
+ return self .long_axis .get_majorticklocs ()
905
912
906
913
def set_ticklabels (self , ticklabels , * , minor = False , ** kwargs ):
907
914
"""
@@ -936,7 +943,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
936
943
**kwargs
937
944
`.Text` properties for the labels.
938
945
"""
939
- self ._long_axis () .set_ticklabels (ticklabels , minor = minor , ** kwargs )
946
+ self .long_axis .set_ticklabels (ticklabels , minor = minor , ** kwargs )
940
947
941
948
def minorticks_on (self ):
942
949
"""
@@ -948,7 +955,7 @@ def minorticks_on(self):
948
955
def minorticks_off (self ):
949
956
"""Turn the minor ticks of the colorbar off."""
950
957
self ._minorlocator = ticker .NullLocator ()
951
- self ._long_axis () .set_minor_locator (self ._minorlocator )
958
+ self .long_axis .set_minor_locator (self ._minorlocator )
952
959
953
960
def set_label (self , label , * , loc = None , ** kwargs ):
954
961
"""
@@ -1013,7 +1020,7 @@ def _set_scale(self, scale, **kwargs):
1013
1020
`matplotlib.scale.register_scale`. These scales can then also
1014
1021
be used here.
1015
1022
"""
1016
- self ._long_axis () ._set_axes_scale (scale , ** kwargs )
1023
+ self .long_axis ._set_axes_scale (scale , ** kwargs )
1017
1024
1018
1025
def remove (self ):
1019
1026
"""
@@ -1285,20 +1292,14 @@ def _get_extension_lengths(self, frac, automin, automax, default=0.05):
1285
1292
1286
1293
def _extend_lower (self ):
1287
1294
"""Return whether the lower limit is open ended."""
1288
- minmax = "max" if self ._long_axis () .get_inverted () else "min"
1295
+ minmax = "max" if self .long_axis .get_inverted () else "min"
1289
1296
return self .extend in ('both' , minmax )
1290
1297
1291
1298
def _extend_upper (self ):
1292
1299
"""Return whether the upper limit is open ended."""
1293
- minmax = "min" if self ._long_axis () .get_inverted () else "max"
1300
+ minmax = "min" if self .long_axis .get_inverted () else "max"
1294
1301
return self .extend in ('both' , minmax )
1295
1302
1296
- def _long_axis (self ):
1297
- """Return the long axis"""
1298
- if self .orientation == 'vertical' :
1299
- return self .ax .yaxis
1300
- return self .ax .xaxis
1301
-
1302
1303
def _short_axis (self ):
1303
1304
"""Return the short axis"""
1304
1305
if self .orientation == 'vertical' :
0 commit comments