Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda