@@ -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 ):
@@ -859,6 +862,17 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
859
862
"""
860
863
Set tick labels.
861
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)`` instead.
870
+
871
+ If you are using this method, you should always fix the tick
872
+ positions before, e.g. by using `.Axis.set_ticks` or by explicitly
873
+ setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
874
+ move and the labels may end up in unexpected positions.
875
+
862
876
Parameters
863
877
----------
864
878
ticklabels : sequence of str or of `.Text`
@@ -874,7 +888,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, update_ticks=True,
874
888
If True, set minor ticks instead of major ticks.
875
889
876
890
**kwargs
877
- Text properties.
891
+ `. Text` properties for the labels .
878
892
"""
879
893
self ._long_axis ().set_ticklabels (ticklabels , minor = minor , ** kwargs )
880
894
0 commit comments