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 adjust sensitivity of y-axis?

I have these y-axis values that I want to plot each on a x-tick using a bar plot to show the difference (the first below value for the x-tick 1, the second value for x-tick 2 and the third for the x-tick 3)

0.9999893294851471
0.9999997569910387
1.0

for now I am trying to get helped by ylim, but in vain:

import matplotlib.pyplot as plt
x=[1,2,3]
y=[0.9999893294851471,0.9999997569910387,1.0]
plt.bar(x,y,align='center') 
plt.plot(x,y, 'r--', label='Default')  
plt.xlabel("tick") 
plt.ylabel("values") 
plt.ylim(0.9999800, 0.9999999) 
plt.show()

Any clues?

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 :

Just add plt.yticks(y) to your code

import matplotlib.pyplot as plt
x=[1,2,3]
y=[0.9999893294851471,0.9999997569910387,1.0]
plt.bar(x,y,align='center') 
plt.plot(x,y, 'r--', label='Default')  
plt.xlabel("tick") 
plt.ylabel("values") 
plt.ylim(0.9999800, 1.0) 
plt.yticks(y)
plt.show()

However, since the values are very vey close, matplotlib adds an offset to the scale, to the ticks refer to this offset.
That’s why you see a value of -0.067, since the scale is 1e-5 with an offset of 9.9999e-1

I’m not sure how you can disable this automatic offset and force matplotlib to show the actual values.

If someone knows how to disable this automatic offset it will be very interesting if an answer handling this could be posted.

enter image description here

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