Search code examples
pythonpandasnumpynatural-logarithm

Understand log scale and actually taking np.log of a data


I am currently working up some experimental data and am having a hard time understanding whether I should be doing a log scale or actually applying np.log onto the data.

Here is the plot I have made.

enter image description here

Blue represents using plt.yscale('log'), whereas the orange is creating a new column and applying np.log onto the data.

My question

Why are their magnitudes so different? Which is correct? and if using plt.yscale('log') is the optimal way to do it, is there a way I can get those values as I need to do a curve fit after?

Thanks in advance for anyone that can provide some answers!

edit(1)

I understand that plt.yscale('log') is in base 10 and np.log refers to the natural log. I have tried using np.log10 on the data instead and it gives a smaller value that does not correspond to using a log scale.


Solution

  • Your data is getting log-ified but "pointing"? in the wrong direction.

    Consider this toy data

    x = np.linspace(0, 1, 100)[:-1]
    y = np.log(1-x) + 5
    

    Then we plot

    plt.plot(x, y)
    

    enter image description here

    If I log scale it:
    It's just more exaggerated

    plt.plot(x, y)
    plt.xscale('log')
    

    enter image description here

    You need to point your data the other direction like normal log data

    plt.plot(-x, y)
    

    enter image description here

    But you also have to make sure the data is positive or ... you know ... logs and stuff ¯\_(ツ)_/¯

    plt.plot(-x + 1, y)
    plt.xscale('log')
    

    enter image description here