Search code examples
python-3.xmatplotliblogarithm

how to show the vertical in logarithmic in matplotlib of python


how to show the vertical in logarithmic in matplotlib in python.

For instance, y is 1,10,100,1000 instead of 1,2,3,....

I need this because I want to show some comparison which one of them is too big for instance one of them reaches 200 in maximum point while the two others reach to maximum 3.5. I need to show clearly difference of two low, also I should show the third in the same figure!


Solution

  • if you use ax:

    import matplotlib.pyplot as plt
    
    x=[1,2,3,4,5,6]
    y=[2,14,56,170,600,1100]
    
    fig, ax = plt.subplots()
    ax.plot(x,y)
    ax.set_yscale('log')
    

    or if you use plt:

    plt.plot(x,y)
    plt.yscale('log')
    plt.show()
    

    enter image description here