How to get matplotlib to write out the full x-axis label form, avoiding scientific notation?

I created a simple hexbin graph with matplotlib.pyplot. I have not changed the default settings. My x-axis information ranges from 2003 to 2009, and y values ​​range from 15 to 35. Instead of writing 2003, 2004, etc., matplotlib collapses it to 0, 1, 2, ... + 2.003 e + 03, Is there an easy way to get matplotlib to write out full numbers?

Thanks,
Mark C.

+7
python matplotlib
source share
1 answer

I think you can use the xticks function to set string labels:

 nums = arange(2003, 2010) xticks(nums, (str(n) for n in nums)) 

EDIT: This is the best way:

 gca().xaxis.set_major_formatter(FormatStrFormatter('%d')) 

or something like that. (In older versions of Matplotlib, the method was called setMajorFormatter .)

+8
source share

All Articles