Skip to content

[Doc]: kwargs in set_ticks when no labels are given #23272

Open
@StefRe

Description

@StefRe

Documentation Link

https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axis.Axis.set_ticks.html?highlight=set_ticks#matplotlib.axis.Axis.set_ticks

Problem

If I want to set the tick label fontsize, I can do the following:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_xticks((0,1,2,3), list('0123'), **{'fontsize': 20})

ax.set_xticks((0,1,2,3), **{'fontsize': 20}) doesn't work as correctly documented:

**kwargs
Text properties for the labels. These take effect only if you pass labels. In other cases, please use tick_params.

So far so good. But if I try ax.tick_params('x', **{'fontsize': 20}) as suggested for this case, I get a ValueError: keyword fontsize is not recognized.

A workaround is

for label in ax.get_xticklabels():
    label.set_fontsize(20)

or using pyplot: plt.xticks(**{'fontsize': 20})

Suggested improvement

The description of kwargs should be changed to something like

Text properties for the labels. These take effect only if you pass labels. In other cases, please use tick_params for the parameters listed there. Other Text parameters can be changed by setting the Text properties of the ticklabels.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions