@@ -1706,10 +1706,16 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
17061706 r"""
17071707 Set the text values of the tick labels.
17081708
1709- .. warning::
1710- This method should only be used after fixing the tick positions
1711- using `.Axis.set_ticks`. Otherwise, the labels may end up in
1712- unexpected positions.
1709+ .. admonition:: Discouraged
1710+
1711+ The use of this method is discouraged, because of the dependency
1712+ on tick positions. In most cases, you'll want to use
1713+ ``set_[x/y]ticks(positions, labels)`` instead.
1714+
1715+ If you are using this method, you should always fix the tick
1716+ positions before, e.g. by using `.Axis.set_ticks` or by explicitly
1717+ setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
1718+ move and the labels may end up in unexpected positions.
17131719
17141720 Parameters
17151721 ----------
@@ -1817,27 +1823,9 @@ def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs):
18171823 kwargs .update (fontdict )
18181824 return self .set_ticklabels (labels , minor = minor , ** kwargs )
18191825
1820- def set_ticks (self , ticks , * , minor = False ):
1821- """
1822- Set this Axis' tick locations.
1823-
1824- If necessary, the view limits of the Axis are expanded so that all
1825- given ticks are visible.
1826+ def _set_tick_locations (self , ticks , * , minor = False ):
1827+ # see docstring of set_ticks
18261828
1827- Parameters
1828- ----------
1829- ticks : list of floats
1830- List of tick locations.
1831- minor : bool, default: False
1832- If ``False``, set the major ticks; if ``True``, the minor ticks.
1833-
1834- Notes
1835- -----
1836- The mandatory expansion of the view limits is an intentional design
1837- choice to prevent the surprise of a non-visible tick. If you need
1838- other limits, you should set the limits explicitly after setting the
1839- ticks.
1840- """
18411829 # XXX if the user changes units, the information will be lost here
18421830 ticks = self .convert_units (ticks )
18431831 if self is self .axes .xaxis :
@@ -1872,6 +1860,37 @@ def set_ticks(self, ticks, *, minor=False):
18721860 self .set_major_locator (mticker .FixedLocator (ticks ))
18731861 return self .get_major_ticks (len (ticks ))
18741862
1863+ def set_ticks (self , ticks , labels = None , * , minor = False , ** kwargs ):
1864+ """
1865+ Set this Axis' tick locations and optionally labels.
1866+
1867+ If necessary, the view limits of the Axis are expanded so that all
1868+ given ticks are visible.
1869+
1870+ Parameters
1871+ ----------
1872+ ticks : list of floats
1873+ List of tick locations.
1874+ labels : list of str, optional
1875+ List of tick labels. If not set, the labels show the data value.
1876+ minor : bool, default: False
1877+ If ``False``, set the major ticks; if ``True``, the minor ticks.
1878+ **kwargs
1879+ `.Text` properties for the labels. These take effect only if you
1880+ pass *labels*. In other cases, please use `~.Axes.tick_params`.
1881+
1882+ Notes
1883+ -----
1884+ The mandatory expansion of the view limits is an intentional design
1885+ choice to prevent the surprise of a non-visible tick. If you need
1886+ other limits, you should set the limits explicitly after setting the
1887+ ticks.
1888+ """
1889+ result = self ._set_tick_locations (ticks , minor = minor )
1890+ if labels is not None :
1891+ self .set_ticklabels (labels , minor = minor , ** kwargs )
1892+ return result
1893+
18751894 def _get_tick_boxes_siblings (self , renderer ):
18761895 """
18771896 Get the bounding boxes for this `.axis` and its siblings
0 commit comments