Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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.
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 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