@@ -1918,15 +1918,17 @@ def set_pickradius(self, pickradius):
1918
1918
def _format_with_dict (tickd , x , pos ):
1919
1919
return tickd .get (x , "" )
1920
1920
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 ):
1922
1923
r"""
1923
- [*Discouraged*] Set the text values of the tick labels.
1924
+ [*Discouraged*] Set this Axis' tick labels with list of string labels.
1924
1925
1925
1926
.. admonition:: Discouraged
1926
1927
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.
1930
1932
1931
1933
If you are using this method, you should always fix the tick
1932
1934
positions before, e.g. by using `.Axis.set_ticks` or by explicitly
@@ -1935,12 +1937,23 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
1935
1937
1936
1938
Parameters
1937
1939
----------
1938
- ticklabels : sequence of str or of `.Text`\s
1940
+ labels : sequence of str or of `.Text`\s
1939
1941
Texts for labeling each tick location in the sequence set by
1940
1942
`.Axis.set_ticks`; the number of labels must match the number of
1941
1943
locations.
1944
+
1942
1945
minor : bool
1943
1946
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
+
1944
1957
**kwargs
1945
1958
Text properties.
1946
1959
@@ -1951,26 +1964,26 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
1951
1964
``tick.label2`` if it is visible, in that order.
1952
1965
"""
1953
1966
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 ]
1956
1969
except TypeError :
1957
- raise TypeError (f"{ ticklabels := } must be a sequence" ) from None
1970
+ raise TypeError (f"{ labels := } must be a sequence" ) from None
1958
1971
locator = (self .get_minor_locator () if minor
1959
1972
else self .get_major_locator ())
1960
1973
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 :
1964
1977
raise ValueError (
1965
1978
"The number of FixedLocator locations"
1966
1979
f" ({ len (locator .locs )} ), usually from a call to"
1967
1980
" 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 )}
1970
1983
func = functools .partial (self ._format_with_dict , tickd )
1971
1984
formatter = mticker .FuncFormatter (func )
1972
1985
else :
1973
- formatter = mticker .FixedFormatter (ticklabels )
1986
+ formatter = mticker .FixedFormatter (labels )
1974
1987
1975
1988
if minor :
1976
1989
self .set_minor_formatter (formatter )
@@ -1982,6 +1995,8 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
1982
1995
ticks = self .get_major_ticks (len (locs ))
1983
1996
1984
1997
ret = []
1998
+ if fontdict is not None :
1999
+ kwargs .update (fontdict )
1985
2000
for pos , (loc , tick ) in enumerate (zip (locs , ticks )):
1986
2001
tick .update_position (loc )
1987
2002
tick_label = formatter (loc , pos )
@@ -2000,47 +2015,6 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
2000
2015
self .stale = True
2001
2016
return ret
2002
2017
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
-
2044
2018
def _set_tick_locations (self , ticks , * , minor = False ):
2045
2019
# see docstring of set_ticks
2046
2020
0 commit comments