Skip to content

[MNT]: Consider deprecating kwargs for set_xticklabels() #23162

Open
@timhoffm

Description

@timhoffm

Summary

In #23158 and similar cases before people use

ticks = ax.get_xticks()
labels = ax.get_xticklabels()
ax.set_xticks(ticks)
ax.set_xticklabels(labels, rotation=90)

to change only the appearance of the ticks. Note that likely the get/set on ticks is inserted here because we have a warning that set_xticklabels chages to a fixed formatter and should only be used with after set_xticks.

The fundamental problem is that this changes to a fixed locator and formatter, which is an unintended side effect if I only want to rotate labels. Additionally, one can get caught up in the lazy determination of the ticks.

It's hard to distinguish between this sort of code and legitimate set_xticklabels calls. I don't think we can be more helpful with runtime warnings.

Proposed fix

A radical suggestion is to take away styling capability from set_xticklabels and instead direct people to tick_params(). The need for set_xticklabels (with it's major intent to set a fixed format - mainly for categorical values) is reduced since you can pass them as x values (plt.bar(['apples', 'peaches'], [1, 3])). I assume there are very few cases that people want a fixed formatter and adapt the style - which would be the only legitimate use for set_xticklabels(labels, rotation=90). They would need to go the extra mile and style separately (set_xticklabels(labels); tick_params('x', rotation=90)). But that might be worth it for removing quite a big foot canon.

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