I want to make some modifications to a few selected tick labels in a plot.
For example, if I do:
label = axes.yaxis.get_major_ticks()[2].label
label
In newer versions of matplotlib
, if you do not set the tick labels with a bunch of str
values, they are ''
by default (and when the plot is draw the labels are simply the ticks values). Knowing that, to get your desired output would require something like this:
>>> from pylab import *
>>> axes = figure().add_subplot(111)
>>> a=axes.get_xticks().tolist()
>>> a[1]='change'
>>> axes.set_xticklabels(a)
[, ,
, ,
, ]
>>> plt.show()
and the result:
and now if you check the _xticklabels
, they are no longer a bunch of ''
.
>>> [item.get_text() for item in axes.get_xticklabels()]
['0.0', 'change', '1.0', '1.5', '2.0']
It works in the versions from 1.1.1rc1
to the current version 2.0
.