@@ -1661,10 +1661,16 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
16611661 r"""
16621662 Set the text values of the tick labels.
16631663
1664- .. warning::
1665- This method should only be used after fixing the tick positions
1666- using `.Axis.set_ticks`. Otherwise, the labels may end up in
1667- unexpected positions.
1664+ .. admonition:: Discouraged
1665+
1666+ The use of this method is discouraged, because of the dependency
1667+ on tick positions. In most cases, you'll want to use
1668+ ``set_[x/y]ticks(positions, labels)`` instead.
1669+
1670+ If you are using this method, you should always fix the tick
1671+ positions before, e.g. by using `.Axis.set_ticks` or by explicitly
1672+ setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
1673+ move and the labels may end up in unexpected positions.
16681674
16691675 Parameters
16701676 ----------
@@ -1772,27 +1778,9 @@ def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs):
17721778 kwargs .update (fontdict )
17731779 return self .set_ticklabels (labels , minor = minor , ** kwargs )
17741780
1775- def set_ticks (self , ticks , * , minor = False ):
1776- """
1777- Set this Axis' tick locations.
1778-
1779- If necessary, the view limits of the Axis are expanded so that all
1780- given ticks are visible.
1781+ def _set_tick_locations (self , ticks , * , minor = False ):
1782+ # see docstring of set_ticks
17811783
1782- Parameters
1783- ----------
1784- ticks : list of floats
1785- List of tick locations.
1786- minor : bool, default: False
1787- If ``False``, set the major ticks; if ``True``, the minor ticks.
1788-
1789- Notes
1790- -----
1791- The mandatory expansion of the view limits is an intentional design
1792- choice to prevent the surprise of a non-visible tick. If you need
1793- other limits, you should set the limits explicitly after setting the
1794- ticks.
1795- """
17961784 # XXX if the user changes units, the information will be lost here
17971785 ticks = self .convert_units (ticks )
17981786 if self is self .axes .xaxis :
@@ -1827,6 +1815,37 @@ def set_ticks(self, ticks, *, minor=False):
18271815 self .set_major_locator (mticker .FixedLocator (ticks ))
18281816 return self .get_major_ticks (len (ticks ))
18291817
1818+ def set_ticks (self , ticks , labels = None , * , minor = False , ** kwargs ):
1819+ """
1820+ Set this Axis' tick locations and optionally labels.
1821+
1822+ If necessary, the view limits of the Axis are expanded so that all
1823+ given ticks are visible.
1824+
1825+ Parameters
1826+ ----------
1827+ ticks : list of floats
1828+ List of tick locations.
1829+ labels : list of str, optional
1830+ List of tick labels. If not set, the labels show the data value.
1831+ minor : bool, default: False
1832+ If ``False``, set the major ticks; if ``True``, the minor ticks.
1833+ **kwargs
1834+ `.Text` properties for the labels. These take effect only if you
1835+ pass *labels*. In other cases, please use `~.Axes.tick_params`.
1836+
1837+ Notes
1838+ -----
1839+ The mandatory expansion of the view limits is an intentional design
1840+ choice to prevent the surprise of a non-visible tick. If you need
1841+ other limits, you should set the limits explicitly after setting the
1842+ ticks.
1843+ """
1844+ result = self ._set_tick_locations (ticks , minor = minor )
1845+ if labels is not None :
1846+ self .set_ticklabels (labels , minor = minor , ** kwargs )
1847+ return result
1848+
18301849 def _get_tick_boxes_siblings (self , renderer ):
18311850 """
18321851 Get the bounding boxes for this `.axis` and its siblings
0 commit comments