@@ -764,7 +764,6 @@ def update_ticks(self):
764764 """
765765 Setup the ticks and ticklabels. This should not be needed by users.
766766 """
767- ax = self .ax
768767 # Get the locator and formatter; defaults to self.locator if not None.
769768 self ._get_ticker_locator_formatter ()
770769 self ._long_axis ().set_major_locator (self .locator )
@@ -817,26 +816,30 @@ def _get_ticker_locator_formatter(self):
817816 _log .debug ('locator: %r' , locator )
818817
819818 @_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 ):
821821 """
822822 Set tick locations.
823823
824824 Parameters
825825 ----------
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`.
834835 """
835836 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 ()
837840 else :
838841 self .locator = ticks
839- self ._long_axis ().set_major_locator (self .locator )
842+ self ._long_axis ().set_major_locator (self .locator )
840843 self .stale = True
841844
842845 def get_ticks (self , minor = False ):
@@ -854,26 +857,41 @@ def get_ticks(self, minor=False):
854857 return self ._long_axis ().get_majorticklocs ()
855858
856859 @_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 ):
858862 """
859863 Set tick labels.
860864
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+
861877 Parameters
862878 ----------
863879 ticklabels : sequence of str or of `.Text`
864880 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.
867883
868884 update_ticks : bool, default: True
869885 This keyword argument is ignored and will be be removed.
870886 Deprecated
887+
888+ minor : bool
889+ If True, set minor ticks instead of major ticks.
890+
891+ **kwargs
892+ `.Text` properties for the labels.
871893 """
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 )
877895
878896 def minorticks_on (self ):
879897 """
0 commit comments