Axis numerical offset in matplotlib
<p>I'm plotting something with matplotlib and it looks like this:</p>

<p><a href="http://i.stack.imgur.com/dvfOn.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/dvfOn.jpg" alt="enter image description here"></a></p>

<p>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'.</p>

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

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

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

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

<p>Here's the code for the plotting:</p>

<pre><code>plt.title(file_name +' at frequency '+ freq + 'MHz')
plt.xlabel('Frequency')
plt.ylabel('Conducted Power (dBm)')
plt.grid(True)
plt.plot(data['x'],data['y'])
#plt.axis([min(data['x']),max(data['x']),min(data['y'],max(data['y']))])
plt.savefig(file_name+'_'+freq)
print('plot written!')
#plt.show()
plt.close('all')
</code></pre>

<p>You need to <code>import</code> certain formatters from <code>matplotlib.ticker</code>. Here is the <a href="http://matplotlib.org/api/ticker_api.html" rel="nofollow">full documentation to ticker</a></p>

<pre><code>from matplotlib.ticker import ScalarFormatter, FormatStrFormatter
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
</code></pre>

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

<p>In general to avoid scientific notation, use the following:</p>

<pre><code>ax.get_xaxis().get_major_formatter().set_scientific(False)
</code></pre>

python matplotlib plot axes graphing