@@ -916,6 +916,12 @@ def set_tick_params(self, which='major', reset=False, **kwargs):
916916
917917 For documentation of keyword arguments, see
918918 :meth:`matplotlib.axes.Axes.tick_params`.
919+
920+ See Also
921+ --------
922+ .Axis.get_tick_params
923+ View the current style settings for ticks, ticklabels, and
924+ gridlines.
919925 """
920926 _api .check_in_list (['major' , 'minor' , 'both' ], which = which )
921927 kwtrans = self ._translate_tick_params (kwargs )
@@ -949,8 +955,62 @@ def set_tick_params(self, which='major', reset=False, **kwargs):
949955
950956 self .stale = True
951957
958+ def get_tick_params (self , which = 'major' ):
959+ """
960+ Get appearance parameters for ticks, ticklabels, and gridlines.
961+
962+ .. versionadded:: 3.7
963+
964+ Parameters
965+ ----------
966+ which : {'major', 'minor'}, default: 'major'
967+ The group of ticks for which the parameters are retrieved.
968+
969+ Returns
970+ -------
971+ dict
972+ Properties for styling tick elements added to the axis.
973+
974+ Notes
975+ -----
976+ This method returns the appearance parameters for styling *new*
977+ elements added to this axis and may be different from the values
978+ on current elements if they were modified directly by the user
979+ (e.g., via ``set_*`` methods on individual tick objects).
980+
981+ Examples
982+ --------
983+ ::
984+
985+ >>> ax.yaxis.set_tick_params(labelsize=30, labelcolor='red',
986+ direction='out', which='major')
987+ >>> ax.yaxis.get_tick_params(which='major')
988+ {'direction': 'out',
989+ 'left': True,
990+ 'right': False,
991+ 'labelleft': True,
992+ 'labelright': False,
993+ 'gridOn': False,
994+ 'labelsize': 30,
995+ 'labelcolor': 'red'}
996+ >>> ax.yaxis.get_tick_params(which='minor')
997+ {'left': True,
998+ 'right': False,
999+ 'labelleft': True,
1000+ 'labelright': False,
1001+ 'gridOn': False}
1002+
1003+
1004+ """
1005+ _api .check_in_list (['major' , 'minor' ], which = which )
1006+ if which == 'major' :
1007+ return self ._translate_tick_params (
1008+ self ._major_tick_kw , reverse = True
1009+ )
1010+ return self ._translate_tick_params (self ._minor_tick_kw , reverse = True )
1011+
9521012 @staticmethod
953- def _translate_tick_params (kw ):
1013+ def _translate_tick_params (kw , reverse = False ):
9541014 """
9551015 Translate the kwargs supported by `.Axis.set_tick_params` to kwargs
9561016 supported by `.Tick._apply_params`.
@@ -961,9 +1021,12 @@ def _translate_tick_params(kw):
9611021
9621022 Returns a new dict of translated kwargs.
9631023
964- Note: The input *kwargs* are currently modified, but that's ok for
965- the only caller.
1024+ Note: Use reverse=True to translate from those supported by
1025+ `.Tick._apply_params` back to those supported by
1026+ `.Axis.set_tick_params`.
9661027 """
1028+ kw_ = {** kw }
1029+
9671030 # The following lists may be moved to a more accessible location.
9681031 allowed_keys = [
9691032 'size' , 'width' , 'color' , 'tickdir' , 'pad' ,
@@ -988,19 +1051,27 @@ def _translate_tick_params(kw):
9881051 'labelright' : 'label2On' ,
9891052 'labeltop' : 'label2On' ,
9901053 }
991- kwtrans = {newkey : kw .pop (oldkey )
992- for oldkey , newkey in keymap .items () if oldkey in kw }
993- if 'colors' in kw :
994- c = kw .pop ('colors' )
1054+ if reverse :
1055+ kwtrans = {
1056+ oldkey : kw_ .pop (newkey )
1057+ for oldkey , newkey in keymap .items () if newkey in kw_
1058+ }
1059+ else :
1060+ kwtrans = {
1061+ newkey : kw_ .pop (oldkey )
1062+ for oldkey , newkey in keymap .items () if oldkey in kw_
1063+ }
1064+ if 'colors' in kw_ :
1065+ c = kw_ .pop ('colors' )
9951066 kwtrans ['color' ] = c
9961067 kwtrans ['labelcolor' ] = c
9971068 # Maybe move the checking up to the caller of this method.
998- for key in kw :
1069+ for key in kw_ :
9991070 if key not in allowed_keys :
10001071 raise ValueError (
10011072 "keyword %s is not recognized; valid keywords are %s"
10021073 % (key , allowed_keys ))
1003- kwtrans .update (kw )
1074+ kwtrans .update (kw_ )
10041075 return kwtrans
10051076
10061077 def set_clip_path (self , clippath , transform = None ):
0 commit comments