Issue
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?
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.
Answered By - Sembei Norimaki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.