You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
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.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 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.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. 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:
Axes
methods:get_xticklabels()
,get_xmajorticklabels()
,get_xminorticklabels()
,get_xgridlines()
,get_xticklines()
(and same for y).Axes.tick_params()
instead where possible.Axis
methods if more control is needed, e.g.ax.xaxis.get_ticklabels()
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
The text was updated successfully, but these errors were encountered: