Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MNT]: Consolidate tick API #29594

Open
Open
@timhoffm

Description

@timhoffm

Summary

The Tick class/concept consistents of aticklabel, atickline (the marker) and agridline. In addition there's thelocation 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 viaax.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 usetick_params() instead where possible, e.g.ax.tick_params(labelsize=10) instead offor 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.
Sincetick_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. useax.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 theAxes methods:get_xticklabels(),get_xmajorticklabels(),get_xminorticklabels(),get_xgridlines(),get_xticklines() (and same for y).
  • Recommend to useAxes.tick_params() instead where possible.
  • Recommend to ues the respectiveAxis 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

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp