@@ -1918,15 +1918,17 @@ def set_pickradius(self, pickradius):
19181918 def _format_with_dict (tickd , x , pos ):
19191919 return tickd .get (x , "" )
19201920
1921- def set_ticklabels (self , ticklabels , * , minor = False , ** kwargs ):
1921+ @_api .rename_parameter ("3.7" , "ticklabels" , "labels" )
1922+ def set_ticklabels (self , labels , * , minor = False , fontdict = None , ** kwargs ):
19221923 r"""
1923- [*Discouraged*] Set the text values of the tick labels.
1924+ [*Discouraged*] Set this Axis' tick labels with list of string labels.
19241925
19251926 .. admonition:: Discouraged
19261927
1927- The use of this method is discouraged, because of the dependency
1928- on tick positions. In most cases, you'll want to use
1929- ``set_[x/y]ticks(positions, labels)`` instead.
1928+ The use of this method is discouraged, because of the dependency on
1929+ tick positions. In most cases, you'll want to use
1930+ ``Axes.set_[x/y/z]ticks(positions, labels)`` or ``Axis.set_ticks``
1931+ instead.
19301932
19311933 If you are using this method, you should always fix the tick
19321934 positions before, e.g. by using `.Axis.set_ticks` or by explicitly
@@ -1935,12 +1937,23 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
19351937
19361938 Parameters
19371939 ----------
1938- ticklabels : sequence of str or of `.Text`\s
1940+ labels : sequence of str or of `.Text`\s
19391941 Texts for labeling each tick location in the sequence set by
19401942 `.Axis.set_ticks`; the number of labels must match the number of
19411943 locations.
1944+
19421945 minor : bool
19431946 If True, set minor ticks instead of major ticks.
1947+
1948+ fontdict : dict, optional
1949+ A dictionary controlling the appearance of the ticklabels.
1950+ The default *fontdict* is::
1951+
1952+ {'fontsize': rcParams['axes.titlesize'],
1953+ 'fontweight': rcParams['axes.titleweight'],
1954+ 'verticalalignment': 'baseline',
1955+ 'horizontalalignment': loc}
1956+
19441957 **kwargs
19451958 Text properties.
19461959
@@ -1951,26 +1964,26 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
19511964 ``tick.label2`` if it is visible, in that order.
19521965 """
19531966 try :
1954- ticklabels = [t .get_text () if hasattr (t , 'get_text' ) else t
1955- for t in ticklabels ]
1967+ labels = [t .get_text () if hasattr (t , 'get_text' ) else t
1968+ for t in labels ]
19561969 except TypeError :
1957- raise TypeError (f"{ ticklabels := } must be a sequence" ) from None
1970+ raise TypeError (f"{ labels := } must be a sequence" ) from None
19581971 locator = (self .get_minor_locator () if minor
19591972 else self .get_major_locator ())
19601973 if isinstance (locator , mticker .FixedLocator ):
1961- # Passing [] as a list of ticklabels is often used as a way to
1962- # remove all tick labels, so only error for > 0 ticklabels
1963- if len (locator .locs ) != len (ticklabels ) and len (ticklabels ) != 0 :
1974+ # Passing [] as a list of labels is often used as a way to
1975+ # remove all tick labels, so only error for > 0 labels
1976+ if len (locator .locs ) != len (labels ) and len (labels ) != 0 :
19641977 raise ValueError (
19651978 "The number of FixedLocator locations"
19661979 f" ({ len (locator .locs )} ), usually from a call to"
19671980 " set_ticks, does not match"
1968- f" the number of ticklabels ({ len (ticklabels )} )." )
1969- tickd = {loc : lab for loc , lab in zip (locator .locs , ticklabels )}
1981+ f" the number of labels ({ len (labels )} )." )
1982+ tickd = {loc : lab for loc , lab in zip (locator .locs , labels )}
19701983 func = functools .partial (self ._format_with_dict , tickd )
19711984 formatter = mticker .FuncFormatter (func )
19721985 else :
1973- formatter = mticker .FixedFormatter (ticklabels )
1986+ formatter = mticker .FixedFormatter (labels )
19741987
19751988 if minor :
19761989 self .set_minor_formatter (formatter )
@@ -1982,6 +1995,8 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
19821995 ticks = self .get_major_ticks (len (locs ))
19831996
19841997 ret = []
1998+ if fontdict is not None :
1999+ kwargs .update (fontdict )
19852000 for pos , (loc , tick ) in enumerate (zip (locs , ticks )):
19862001 tick .update_position (loc )
19872002 tick_label = formatter (loc , pos )
@@ -2000,47 +2015,6 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
20002015 self .stale = True
20012016 return ret
20022017
2003- # Wrapper around set_ticklabels used to generate Axes.set_x/ytickabels; can
2004- # go away once the API of Axes.set_x/yticklabels becomes consistent.
2005- def _set_ticklabels (self , labels , * , fontdict = None , minor = False , ** kwargs ):
2006- """
2007- Set this Axis' labels with list of string labels.
2008-
2009- .. warning::
2010- This method should only be used after fixing the tick positions
2011- using `.Axis.set_ticks`. Otherwise, the labels may end up in
2012- unexpected positions.
2013-
2014- Parameters
2015- ----------
2016- labels : list of str
2017- The label texts.
2018-
2019- fontdict : dict, optional
2020- A dictionary controlling the appearance of the ticklabels.
2021- The default *fontdict* is::
2022-
2023- {'fontsize': rcParams['axes.titlesize'],
2024- 'fontweight': rcParams['axes.titleweight'],
2025- 'verticalalignment': 'baseline',
2026- 'horizontalalignment': loc}
2027-
2028- minor : bool, default: False
2029- Whether to set the minor ticklabels rather than the major ones.
2030-
2031- Returns
2032- -------
2033- list of `.Text`
2034- The labels.
2035-
2036- Other Parameters
2037- ----------------
2038- **kwargs : `~.text.Text` properties.
2039- """
2040- if fontdict is not None :
2041- kwargs .update (fontdict )
2042- return self .set_ticklabels (labels , minor = minor , ** kwargs )
2043-
20442018 def _set_tick_locations (self , ticks , * , minor = False ):
20452019 # see docstring of set_ticks
20462020
0 commit comments