[Python] Matplotlib log(log(x)) scale

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    I need a plot which doesn't fit the usual 'log-log' definition, but has a linear x scale and a double logarithmic y scale. I tried to create this in matplotlib with

    import numpy as np
    from matplotlib import pyplot as plt

    # constants that result from other part of program
    b = 9.144
    c = -3.579

    # values for plot
    XL = np.linspace(273.15,373.15,101)
    YL = 10 ** 10 ** (b + c * np.log10(XL)) - 0.7

    # functions for scale transformation
    def fw(x):
    return np.log10(np.log10(x))

    def bw(x):
    return 10 ** 10 ** x

    plt.plot(XL - 273.15, YL)
    plt.yscale('function', functions=(fw, bw))
    plt.show()


    Please find this image for reference. However this program has two problems:

    1. The y axis ticks start at 100 for a reason that I do not understand, leaving the largest part of the graph without any ticks.
    2. I get the following warnings from NumPy regarding the log10 calls from fw(x):

    RuntimeWarning: divide by zero encountered in log10
    return np.log10(np.log10(x))
    RuntimeWarning: invalid value encountered in log10
    return np.log10(np.log10(x))


    I get that probably the first warning leads to the second, but I do not see why there would be a division by zero. Any assistance to enlightenment on both problems would be greatly appreciated.

    Continue reading...

Compartilhe esta Página