@@ -817,26 +817,30 @@ def _get_ticker_locator_formatter(self):
817
817
_log .debug ('locator: %r' , locator )
818
818
819
819
@_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 ):
821
822
"""
822
823
Set tick locations.
823
824
824
825
Parameters
825
826
----------
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`.
834
836
"""
835
837
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 ()
837
841
else :
838
842
self .locator = ticks
839
- self ._long_axis ().set_major_locator (self .locator )
843
+ self ._long_axis ().set_major_locator (self .locator )
840
844
self .stale = True
841
845
842
846
def get_ticks (self , minor = False ):
@@ -859,6 +863,17 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
859
863
"""
860
864
Set tick labels.
861
865
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
+
862
877
Parameters
863
878
----------
864
879
ticklabels : sequence of str or of `.Text`
@@ -874,7 +889,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
874
889
If True, set minor ticks instead of major ticks.
875
890
876
891
**kwargs
877
- Text properties.
892
+ `. Text` properties for the labels .
878
893
"""
879
894
self ._long_axis ().set_ticklabels (ticklabels , minor = minor , ** kwargs )
880
895
0 commit comments