Brocolli Rob Brocolli Rob - 1 year ago 181
Python Question

Axis numerical offset in matplotlib

I'm plotting something with matplotlib and it looks like this:

enter image description here

I can't seem to figure out why the x-axis is offset like it is...It looks like it's saying, 'whatever you read from me, add 2.398e9 to it for the actual x value'.

This is not quite what I want...Can I make it take only the first 4 digits, instead?

This is representing frequency, so I'd like to see something that reads:

2000 or 2400 or 2800....I can add the 'MHz' part in the axis title...But, this is unreadable at a glance.

Is this doing this because it's trying to make decisions on how to truncate long data?

Here's the code for the plotting:

plt.title(file_name +' at frequency '+ freq + 'MHz')
plt.ylabel('Conducted Power (dBm)')
print('plot written!')

Answer Source

You need to import certain formatters from matplotlib.ticker. Here is the full documentation to ticker

from matplotlib.ticker import ScalarFormatter, FormatStrFormatter

Once you have set this to your plot likewise, you should be able to see the +2.398e9 disappear.

In general to avoid scientific notation, use the following:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download