如何强制 matplotlib 写出 x 轴标签的完整形式,避免科学记数法? [英] How do I force matplotlib to write out the full form of the x-axis label, avoiding scientific notation?

查看:22
本文介绍了如何强制 matplotlib 写出 x 轴标签的完整形式,避免科学记数法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 matplotlib.pyplot 创建了一个简单的 hexbin 图.我没有更改任何默认设置.我的 x 轴信息范围是 2003 到 2009,而 y 值范围是 15 到 35.而不是写出 2003、2004 等,matplotlib 将其折叠为 0、1、2、... + 2.003e+03.有没有一种简单的方法可以强制 matplotlib 写出完整的数字?

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?

谢谢,
马克 C.

Thanks,
Mark C.

推荐答案

我认为您可以使用 xticks 函数设置字符串标签:

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

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

这是一个更好的方法:

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

或类似的东西.(在较旧的Matplotlib版本中,该方法称为 setMajorFormatter .)

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

这篇关于如何强制 matplotlib 写出 x 轴标签的完整形式,避免科学记数法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆