Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Accessing Matplotlib Text Object Label Text

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.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

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()))
over 4 years ago · Santiago Trujillo Denunciar

0

The labels you are iterating over from get_ticklabels() are matplotlib.text.Text objects. To access the actual text in that object, you can use get_text().

So, something like this should work:

for label in ax.xaxis.get_ticklabels()[1::2]:
    print(len(label.get_text()))

Note that this length may include special characters (e.g. latex $ mathmode delimiters) as it is the length of the raw text string

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda