-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
This is a placeholder issue so that I don't forget about it. I will some time later implement a draft PR. However, feedback is already welcome.
Problem statement
Axis.set_ticklabels() (and the derived Axes.set_x/yticklabels()) are problematic as they change the text of existing ticks. This relies implicitly on ticks being set previously at adequate positions. Essentially set_ticklabels() can only be used reasonably if set_ticks() has been called before. We try to make users aware of this by a warning in https://matplotlib.org/3.3.3/api/_as_gen/matplotlib.axis.Axis.set_ticklabels.html.
Proposed fix
-
Add a parameter
labelstoAxis.set_ticks()so that one can doax.set_xticks([1, 2, 3], labels=['a', 'b', 'c'])instead of
ax.set_xticks([1, 2, 3]) ax.set_xticklabels(['a', 'b', 'c']) -
Discourage using
set_ticklabels(). - I think it's too widely used, so that we cannot deprecate it.
Further comments
This should make set_xticks() more similar/equal to pyplot.xticks(), which already has the labels parameter.
To be sorted out:
- whether we want to support labels only (set_ticks(labels=['a', 'b', 'c'])
- the return value of
get_xicks(), which only returns the values, whereaspyplot.xticks()without parameters returnsticks, labels. This is a somwhat annoying asymmetry, but probably has to be left as is. - some more details.