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 labels to Axis.set_ticks() so that one can do
ax.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, whereas pyplot.xticks() without parameters returns ticks, labels. This is a somwhat annoying asymmetry, but probably has to be left as is.
- some more details.
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 derivedAxes.set_x/yticklabels()) are problematic as they change the text of existing ticks. This relies implicitly on ticks being set previously at adequate positions. Essentiallyset_ticklabels()can only be used reasonably ifset_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 doinstead of
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 topyplot.xticks(), which already has the labels parameter.To be sorted out:
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.