@@ -1661,10 +1661,16 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
1661
1661
r"""
1662
1662
Set the text values of the tick labels.
1663
1663
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.
1668
1674
1669
1675
Parameters
1670
1676
----------
@@ -1772,27 +1778,9 @@ def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs):
1772
1778
kwargs .update (fontdict )
1773
1779
return self .set_ticklabels (labels , minor = minor , ** kwargs )
1774
1780
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
1781
1783
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
- """
1796
1784
# XXX if the user changes units, the information will be lost here
1797
1785
ticks = self .convert_units (ticks )
1798
1786
if self is self .axes .xaxis :
@@ -1827,6 +1815,37 @@ def set_ticks(self, ticks, *, minor=False):
1827
1815
self .set_major_locator (mticker .FixedLocator (ticks ))
1828
1816
return self .get_major_ticks (len (ticks ))
1829
1817
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
+
1830
1849
def _get_tick_boxes_siblings (self , renderer ):
1831
1850
"""
1832
1851
Get the bounding boxes for this `.axis` and its siblings
0 commit comments