@@ -817,26 +817,30 @@ def _get_ticker_locator_formatter(self):
817817 _log .debug ('locator: %r' , locator )
818818
819819 @_api .delete_parameter ("3.5" , "update_ticks" )
820- def set_ticks (self , ticks , update_ticks = True ):
820+ def set_ticks (self , ticks , update_ticks = True , labels = None , * ,
821+ minor = False , ** kwargs ):
821822 """
822823 Set tick locations.
823824
824825 Parameters
825826 ----------
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-
827+ ticks : list of floats
828+ List of tick locations.
829+ labels : list of str, optional
830+ List of tick labels. If not set, the labels show the data value.
831+ minor : bool, default: False
832+ If ``False``, set the major ticks; if ``True``, the minor ticks.
833+ **kwargs
834+ `.Text` properties for the labels. These take effect only if you
835+ pass *labels*. In other cases, please use `~.Axes.tick_params`.
834836 """
835837 if np .iterable (ticks ):
836- self .locator = ticker .FixedLocator (ticks , nbins = len (ticks ))
838+ self ._long_axis ().set_ticks (ticks , labels = labels , minor = minor ,
839+ ** kwargs )
840+ self .locator = self ._long_axis ().get_major_locator ()
837841 else :
838842 self .locator = ticks
839- self ._long_axis ().set_major_locator (self .locator )
843+ self ._long_axis ().set_major_locator (self .locator )
840844 self .stale = True
841845
842846 def get_ticks (self , minor = False ):
@@ -859,6 +863,17 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
859863 """
860864 Set tick labels.
861865
866+ .. admonition:: Discouraged
867+
868+ The use of this method is discouraged, because of the dependency
869+ on tick positions. In most cases, you'll want to use
870+ ``set_ticks(positions, labels)`` instead.
871+
872+ If you are using this method, you should always fix the tick
873+ positions before, e.g. by using `.Axis.set_ticks` or by explicitly
874+ setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
875+ move and the labels may end up in unexpected positions.
876+
862877 Parameters
863878 ----------
864879 ticklabels : sequence of str or of `.Text`
@@ -874,7 +889,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
874889 If True, set minor ticks instead of major ticks.
875890
876891 **kwargs
877- Text properties.
892+ `. Text` properties for the labels .
878893 """
879894 self ._long_axis ().set_ticklabels (ticklabels , minor = minor , ** kwargs )
880895
0 commit comments