[Python] Matplotlib could not convert string to float when iterating through tick labels

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to run code to modify the y ticks of a matplotlib plot:

    fig, ax = plt.subplots()
    ax.plot([1,2,3], [-50, 50, 100])
    # Divide y tick labels by 10
    ax.set_yticklabels([int(float(label.get_text())/10) for label in ax.get_yticklabels()])


    But I got the error: ValueError: could not convert string to float: '−60'

    Continue reading...

Compartilhe esta Página