简体   繁体   中英

How do I force matplotlib to write out the full form of the x-axis label, avoiding scientific notation?

I've created a simple hexbin plot with matplotlib.pyplot. I haven't changed any default settings. My x-axis information ranges from 2003 to 2009, while the y values range from 15 to 35. Rather than writing out 2003, 2004, etc., matplotlib collapses it into 0, 1, 2, ... + 2.003e+03. Is there a simple way to force matplotlib to write out the full numbers?

Thanks,
Mark C.

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 a better way:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM