Skip to content

Commit 249f2ca

Browse files
committed
Update docstrings; add test case.
1 parent 48910ca commit 249f2ca

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,8 @@ def tick_params(self, axis='both', **kwargs):
33263326
Change the appearance of ticks, tick labels, and gridlines.
33273327
33283328
Tick properties that are not explicitly set using the keyword
3329-
arguments remain unchanged unless *reset* is True.
3329+
arguments remain unchanged unless *reset* is True. For the current
3330+
style defaults, see :meth:`matplotlib.axis.Axis.get_tick_params`.
33303331
33313332
Parameters
33323333
----------
@@ -3400,23 +3401,6 @@ def tick_params(self, axis='both', **kwargs):
34003401
ykw.pop('labelbottom', None)
34013402
self.yaxis.set_tick_params(**ykw)
34023403

3403-
def get_tick_params(self, axis, which='major'):
3404-
"""
3405-
Get the appearance of ticks, tick labels, and gridlines.
3406-
3407-
Parameters
3408-
----------
3409-
axis : {'x', 'y'}
3410-
The axis to which the parameters are applied.
3411-
which : {'major', 'minor'}, default: 'major'
3412-
The group of ticks to which the parameters are applied.
3413-
3414-
"""
3415-
_api.check_in_list(['x', 'y'], axis=axis)
3416-
if axis == 'x':
3417-
return self.xaxis.get_tick_params(which=which)
3418-
return self.yaxis.get_tick_params(which=which)
3419-
34203404
def set_axis_off(self):
34213405
"""
34223406
Turn the x- and y-axis off.

lib/matplotlib/axis.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ def set_tick_params(self, which='major', reset=False, **kwargs):
940940
941941
For documentation of keyword arguments, see
942942
:meth:`matplotlib.axes.Axes.tick_params`.
943+
944+
See Also
945+
--------
946+
:meth:`.Axis.get_tick_params`
947+
View the current style defaults for ticks, ticklabels, and
948+
gridlines.
943949
"""
944950
_api.check_in_list(['major', 'minor', 'both'], which=which)
945951
kwtrans = self._translate_tick_params(kwargs)
@@ -977,8 +983,18 @@ def get_tick_params(self, which='major'):
977983
"""
978984
Get appearance parameters for ticks, ticklabels, and gridlines.
979985
980-
For documentation of keyword arguments, see
981-
:meth:`matplotlib.axes.Axes.get_tick_params`.
986+
Parameters
987+
----------
988+
which : {'major', 'minor'}, default: 'major'
989+
The group of ticks to which the parameters are applied.
990+
991+
Notes
992+
-----
993+
This method returns the default values for styling *new* elements
994+
added to this axis and may be different from the values on current
995+
elements, if they were modified directly by the user (e.g., via
996+
``set_*`` methods on individual tick objects).
997+
982998
"""
983999
_api.check_in_list(['major', 'minor'], which=which)
9841000
if which == 'major':

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6377,6 +6377,24 @@ def test_tick_apply_tickdir_deprecation():
63776377
tick.apply_tickdir('out')
63786378

63796379

6380+
def test_axis_get_tick_params():
6381+
axis = plt.subplot().yaxis
6382+
initial_major_style = {**axis.get_tick_params(which='major')}
6383+
initial_minor_style = {**axis.get_tick_params(which='minor')}
6384+
6385+
assert axis._major_tick_kw == initial_major_style
6386+
assert axis._minor_tick_kw == initial_minor_style
6387+
axis.set_tick_params(labelsize=30, labelcolor='red',
6388+
direction='out', which='both')
6389+
6390+
new_major_style = {**axis.get_tick_params(which='major')}
6391+
new_minor_style = {**axis.get_tick_params(which='minor')}
6392+
assert initial_major_style != new_major_style
6393+
assert axis._major_tick_kw == new_major_style
6394+
assert initial_minor_style != new_minor_style
6395+
assert axis._minor_tick_kw == new_minor_style
6396+
6397+
63806398
def test_axis_set_tick_params_labelsize_labelcolor():
63816399
# Tests fix for issue 4346
63826400
axis_1 = plt.subplot()

0 commit comments

Comments
 (0)