Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MNT]: Consolidate tick API #29594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
timhoffm opened this issue Feb 8, 2025 · 0 comments
Open

[MNT]: Consolidate tick API #29594

timhoffm opened this issue Feb 8, 2025 · 0 comments

Comments

@timhoffm
Copy link
Member

timhoffm commented Feb 8, 2025

Summary

The Tick class/concept consistents of a ticklabel, a tickline (the marker) and a gridline. In addition there's the location as a fundmental property.

We have a lot of methods to handle ticks. There are methods on Axis to configure all these properties - often in flavors of major/minor and global (i.e. a function that lets you select major/minor/both). These methods would typically be used via ax.xaxis.get_majorticklabels(). Additionally, a subset of these wrappers is exposed on the Axes level, then in the flavors of x/y.

Image

Overall we have 16 such methods on Axes and 14 on Axis that directly work on Tick instances or parts of them.

Proposed fix

We should discourage direct interaction with ticks or their components (ticklabel, tickline, gridline). As ticks are volatile configuring the instances explicitly may not persist if the plot is changed later.

Therefore, I would like to get rid of the high-level Axes methods that give access to these components: get_xticklabels(), get_xmajorticklabels(), get_xminorticklabels(), get_xgridlines(), get_xticklines() (and same for y).

People should use tick_params() instead where possible, e.g. ax.tick_params(labelsize=10) instead of for label in ax.get_xticklabels(): label.set_fontsize(10). This is not only shorter but also configures the common/universal tick property instead of individual volatile instances.
Since tick_params() does currently not, and likely will never provide full control on all aspects (e.g. this example makes tick labels pickable), users should use the underlying Axis functions if they really must access the indivdual tick(components), i.e. use ax.xaxis.get_ticklabels() instead of ax.get_xticklabels()`.

While removing this bunch of wrapper functions on Axes is massive API change, I think we eventually want to go there (slowly through a pending deprecation), because these functions are encouraging nowadays bad practice. - The weaker alternative would be to only discourage.

Concrete:

  • pending deprecate the Axes methods: get_xticklabels(), get_xmajorticklabels(), get_xminorticklabels(), get_xgridlines(), get_xticklines() (and same for y).
  • Recommend to use Axes.tick_params() instead where possible.
  • Recommend to ues the respective Axis methods if more control is needed, e.g. ax.xaxis.get_ticklabels()
  • On all methods that return Tick components, warn that this only affects the current instances and future changes to the plot may create new ticks.

Usage statistics from GitHub query
Query string: /\.get_gridlines\(/ NOT path:_base.py NOT path:axes.py NOT path:axis.py language:Python NOT is:fork NOT repo:matplotlib/matplotlib

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant