Search code examples
pythonchartslineyaxis

want to set y-axis label values in line chart


line chart

want to display the yaxis label in the range 0.2 to 0.8 in the range of 0.2.

example: 0.2, 0.4, 0.6, 0.8

code:

plt.axis=([0,0.45,0.2,0.8])
plt.plot([0.2,0.25,0.3,0.35,0.4,0.45],[0.5,0.6,0.60,0.5,0.5,0.6])

Solution

  • This can be setted with yticks and np.arrange as follows:

    import matplotlib.pyplot as plt
    import numpy as np
    
    plt.plot([0.2,0.25,0.3,0.35,0.4,0.45],[0.5,0.6,0.60,0.5,0.5,0.6])
    plt.yticks(np.arange(0.2, 0.8, step=0.2))
    plt.show()
    

    plot Here is the documentation for yticks

    Hope it helps!