@@ -764,7 +764,6 @@ def update_ticks(self):
764
764
"""
765
765
Setup the ticks and ticklabels. This should not be needed by users.
766
766
"""
767
- ax = self .ax
768
767
# Get the locator and formatter; defaults to self.locator if not None.
769
768
self ._get_ticker_locator_formatter ()
770
769
self ._long_axis ().set_major_locator (self .locator )
@@ -817,26 +816,30 @@ def _get_ticker_locator_formatter(self):
817
816
_log .debug ('locator: %r' , locator )
818
817
819
818
@_api .delete_parameter ("3.5" , "update_ticks" )
820
- def set_ticks (self , ticks , update_ticks = True ):
819
+ def set_ticks (self , ticks , update_ticks = True , labels = None , * ,
820
+ minor = False , ** kwargs ):
821
821
"""
822
822
Set tick locations.
823
823
824
824
Parameters
825
825
----------
826
- ticks : array-like or `~matplotlib.ticker.Locator` or None
827
- The tick positions can be hard-coded by an array of values; or
828
- they can be defined by a `.Locator`. Setting to *None* reverts
829
- to using a default locator.
830
-
831
- update_ticks : bool, default: True
832
- As of 3.5 this has no effect.
833
-
826
+ ticks : list of floats
827
+ List of tick locations.
828
+ labels : list of str, optional
829
+ List of tick labels. If not set, the labels show the data value.
830
+ minor : bool, default: False
831
+ If ``False``, set the major ticks; if ``True``, the minor ticks.
832
+ **kwargs
833
+ `.Text` properties for the labels. These take effect only if you
834
+ pass *labels*. In other cases, please use `~.Axes.tick_params`.
834
835
"""
835
836
if np .iterable (ticks ):
836
- self .locator = ticker .FixedLocator (ticks , nbins = len (ticks ))
837
+ self ._long_axis ().set_ticks (ticks , labels = labels , minor = minor ,
838
+ ** kwargs )
839
+ self .locator = self ._long_axis ().get_major_locator ()
837
840
else :
838
841
self .locator = ticks
839
- self ._long_axis ().set_major_locator (self .locator )
842
+ self ._long_axis ().set_major_locator (self .locator )
840
843
self .stale = True
841
844
842
845
def get_ticks (self , minor = False ):
@@ -854,26 +857,41 @@ def get_ticks(self, minor=False):
854
857
return self ._long_axis ().get_majorticklocs ()
855
858
856
859
@_api .delete_parameter ("3.5" , "update_ticks" )
857
- def set_ticklabels (self , ticklabels , update_ticks = True ):
860
+ def set_ticklabels (self , ticklabels , update_ticks = True , * , minor = False ,
861
+ ** kwargs ):
858
862
"""
859
863
Set tick labels.
860
864
865
+ .. admonition:: Discouraged
866
+
867
+ The use of this method is discouraged, because of the dependency
868
+ on tick positions. In most cases, you'll want to use
869
+ ``set_ticks(positions, labels=labels)`` instead.
870
+
871
+ If you are using this method, you should always fix the tick
872
+ positions before, e.g. by using `.Colorbar.set_ticks` or by
873
+ explicitly setting a `~.ticker.FixedLocator` on the long axis
874
+ of the colorbar. Otherwise, ticks are free to move and the
875
+ labels may end up in unexpected positions.
876
+
861
877
Parameters
862
878
----------
863
879
ticklabels : sequence of str or of `.Text`
864
880
Texts for labeling each tick location in the sequence set by
865
- `.Axis .set_ticks`; the number of labels must match the number of
866
- locations.
881
+ `.Colorbar .set_ticks`; the number of labels must match the number
882
+ of locations.
867
883
868
884
update_ticks : bool, default: True
869
885
This keyword argument is ignored and will be be removed.
870
886
Deprecated
887
+
888
+ minor : bool
889
+ If True, set minor ticks instead of major ticks.
890
+
891
+ **kwargs
892
+ `.Text` properties for the labels.
871
893
"""
872
- if isinstance (self .locator , ticker .FixedLocator ):
873
- self .formatter = ticker .FixedFormatter (ticklabels )
874
- else :
875
- _api ._warn_external ("set_ticks() must have been called." )
876
- self .stale = True
894
+ self ._long_axis ().set_ticklabels (ticklabels , minor = minor , ** kwargs )
877
895
878
896
def minorticks_on (self ):
879
897
"""
0 commit comments