Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force pyplot to show actual axis values [duplicate]

I am using Python and Pyplot to produce a plot. The y axis of the plot is generated automatically, and works fine.

If the range is small however, the y axis will produce values such as:

0.00005,  
0.00010,  
0.00015,  
0.00020,  
0.00025,  
0.00030, 

and then at the top of the axis, will say:

+1.543e-1

I would prefer that it just explicitly shows the values:

0.15435  
0.15440  
0.15445  
0.15450  
0.15455  
0.15460  

Could someone tell me how to do this please?

like image 710
user1551817 Avatar asked Jan 30 '26 01:01

user1551817


1 Answers

Alright, I think I found the total solution:

Here is a quick plot that recreates your problem:

plot((0.15435,0.15440,0.15445,0.15450,0.15455,0.15460),(0.15435,0.15440,0.15445,0.15450,0.15455,0.15460))

The following code (similar to how it was as shown here) should adjust the ticker like you want:

y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
gca().yaxis.set_major_formatter(y_formatter)
like image 71
Chris Zeh Avatar answered Feb 01 '26 13:02

Chris Zeh