[Python] How do I create a secondary axis based on on a complex conversion?

Discussão em 'Python' iniciado por Stack, Janeiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a secondary axis for my plot. I can get all of my lines to plot on the graph (y1 to y14) and all y values are in the same units. The conversion to a secondary unit is essentially "exp(y/7)." I struggled with this long enough to resort to chatgpt, which gave me the following after lengthy troubleshoointg:

    def y_to_secondary(y):
    return np.asarray(math.exp(np.asarray(y1)/(7)))

    def secondary_to_y(secondary):
    return 7*math.log(np.asarray(secondary))

    secay = ax1.secondary_yaxis('right', functions=(y_to_secondary, secondary_to_y))


    I continue to get the error: TypeError: only size-1 arrays can be converted to Python scalars

    I am defining my original arrays as followed:

    y1=[]
    T1=[]
    for a in range(2,1000):
    y1.append(-7 + (2*a))


    Any ideas how to fix the problem?

    Continue reading...

Compartilhe esta Página