Attempting to access the length of a matplotlib axis label with this code:
for label in ax.xaxis.get_ticklabels()[1::2]:
print(len(label))
However I am getting an error that the object does not have a length attribute. print(label[2])
also errors out with a similar error.
text. Text objects. To access the actual text in that object, you can use get_text() .
horizontalalignment or ha. [ 'center' | 'right' | 'left' ] label. any string. linespacing.
BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox. In your case, the transform itself is based upon a TransformedBBox which again has a Bbox upon which it is based and a transform - for this nested instance an Affine2D transform.
Matplotlib's text objects can't be accessed through standard indexing - what you're looking for is the get_text()
attribute found in the text object documentation. E.g.
for label in ax.xaxis.get_tick_labels()[1::2]:
print(len(label.get_text()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With