【问题标题】:How do I force matplotlib to write out the full form of the x-axis label, avoiding scientific notation?如何强制 matplotlib 写出 x 轴标签的完整形式,避免使用科学记数法?
【发布时间】:2010-07-18 03:26:48
【问题描述】:

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

谢谢,
马克 C。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我认为你可以使用xticks function 来设置字符串标签:

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

    编辑:这是一个更好的方法:

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

    或类似的东西,无论如何。 (在旧版本的 Matplotlib 中,该方法称为 setMajorFormatter。)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多