Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update docstrings; add test case.
  • Loading branch information
stefmolin committed Sep 5, 2022
commit 249f2ca2a9e15061e4c2684e546d722581f67a14
20 changes: 2 additions & 18 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,8 @@ def tick_params(self, axis='both', **kwargs):
Change the appearance of ticks, tick labels, and gridlines.

Tick properties that are not explicitly set using the keyword
arguments remain unchanged unless *reset* is True.
arguments remain unchanged unless *reset* is True. For the current
style defaults, see :meth:`matplotlib.axis.Axis.get_tick_params`.
Comment thread
stefmolin marked this conversation as resolved.
Outdated

Parameters
----------
Expand Down Expand Up @@ -3400,23 +3401,6 @@ def tick_params(self, axis='both', **kwargs):
ykw.pop('labelbottom', None)
self.yaxis.set_tick_params(**ykw)

def get_tick_params(self, axis, which='major'):
"""
Get the appearance of ticks, tick labels, and gridlines.

Parameters
----------
axis : {'x', 'y'}
The axis to which the parameters are applied.
which : {'major', 'minor'}, default: 'major'
The group of ticks to which the parameters are applied.

"""
_api.check_in_list(['x', 'y'], axis=axis)
if axis == 'x':
return self.xaxis.get_tick_params(which=which)
return self.yaxis.get_tick_params(which=which)

def set_axis_off(self):
"""
Turn the x- and y-axis off.
Expand Down
20 changes: 18 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@ def set_tick_params(self, which='major', reset=False, **kwargs):

For documentation of keyword arguments, see
:meth:`matplotlib.axes.Axes.tick_params`.

See Also
--------
:meth:`.Axis.get_tick_params`
Comment thread
stefmolin marked this conversation as resolved.
Outdated
View the current style defaults for ticks, ticklabels, and
Comment thread
stefmolin marked this conversation as resolved.
Outdated
gridlines.
"""
_api.check_in_list(['major', 'minor', 'both'], which=which)
kwtrans = self._translate_tick_params(kwargs)
Expand Down Expand Up @@ -977,8 +983,18 @@ def get_tick_params(self, which='major'):
"""
Get appearance parameters for ticks, ticklabels, and gridlines.

For documentation of keyword arguments, see
:meth:`matplotlib.axes.Axes.get_tick_params`.
Parameters
----------
which : {'major', 'minor'}, default: 'major'
The group of ticks to which the parameters are applied.

Comment thread
stefmolin marked this conversation as resolved.
Notes
-----
This method returns the default values for styling *new* elements
added to this axis and may be different from the values on current
elements, if they were modified directly by the user (e.g., via
``set_*`` methods on individual tick objects).

"""
_api.check_in_list(['major', 'minor'], which=which)
if which == 'major':
Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6377,6 +6377,24 @@ def test_tick_apply_tickdir_deprecation():
tick.apply_tickdir('out')


def test_axis_get_tick_params():
axis = plt.subplot().yaxis
initial_major_style = {**axis.get_tick_params(which='major')}
initial_minor_style = {**axis.get_tick_params(which='minor')}

assert axis._major_tick_kw == initial_major_style
assert axis._minor_tick_kw == initial_minor_style
axis.set_tick_params(labelsize=30, labelcolor='red',
direction='out', which='both')

new_major_style = {**axis.get_tick_params(which='major')}
new_minor_style = {**axis.get_tick_params(which='minor')}
assert initial_major_style != new_major_style
assert axis._major_tick_kw == new_major_style
assert initial_minor_style != new_minor_style
assert axis._minor_tick_kw == new_minor_style


def test_axis_set_tick_params_labelsize_labelcolor():
# Tests fix for issue 4346
axis_1 = plt.subplot()
Expand Down