Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set tick frequency of ylim in matplotlib

I have the following for graph blot. I need the ylim to be step size of 10 and should start from 10 till 70 as shown in figure.

plt.figure(figsize=(3,2))
no = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]


measured_tech_1= [37.506, 37.506, 37.506, 37.506, 37.506, 37.506, 37.506, 37.506, 37.506, 37.506, 37.506,37.506, 37.506]
predicted_tech_1= [38.811, 38.811, 38.811, 38.811, 38.811, 38.811, 38.811, 38.811, 38.811, 38.811, 38.811,38.811, 38.811]
measured_tech_2 = [4.735, 8.451, 10.702, 12.857, 14.900, 16.908, 19.233, 21.328, 23.351, 25.403, 27.580, 29.939,32.832]
predicted_tech_2 = [2.945, 6.989, 8.294, 10.968, 13.643, 16.506, 19.261, 21.658, 24.056, 26.454, 29.175, 32.240,34.795]
measured_tech_3 = [38.495, 38.495, 38.495, 38.495, 38.495, 38.771, 38.771, 38.771, 38.771, 38.616, 38.616, 38.616,38.616]
predicted_tech_3 = [35.255, 35.351, 35.463, 35.492, 35.181, 35.410, 35.483, 35.453, 35.329, 35.146, 34.6130,35.407, 35.500]

plt.plot(no,measured_tech_1 , color='orange', marker='^',linestyle='dashed',label='Measured-Technique 1')
plt.plot(no,predicted_tech_1 , color='orange', marker='*',linestyle='dashed',label='Predicted-Technique 1')

plt.plot(no, measured_tech_2, color='purple', marker='^', linestyle='dashed',label='Measured-Technique 2')
plt.plot(no, predicted_tech_2, color='purple', marker='*'linestyle='dashed',label='Predicted-Technique 2')

plt.plot(no, measured_tech_3, color='green', marker='^',linestyle='dashed',label='Measured-Technique 3')
plt.plot(no, predicted_tech_3, color='green', marker='*',linestyle='dashed',label='Predicted-Technique 3')

plt.ylim(10, 70)

plt.xticks(no,fontsize='8')
plt.legend(loc='upper right',prop={'size': 3.5})
plt.xlabel('No.')
plt.ylabel('Latency')

Figure

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use one of the tick locators. In this case MultipleLocator is probably simplest:

from matplotlib import ticker
plt.gca().yaxis.set_major_locator(ticker.MultipleLocator(10))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading