How to remove relative shift in matplotlib axis

前端 未结 2 772
轻奢々
轻奢々 2020-11-22 15:18

When I try to do a plot against a range with big enough numbers I get an axis with relative shift for all the ticks. For example:

plot([1000, 1001, 1002], [1         


        
相关标签:
2条回答
  • 2020-11-22 16:15

    To disable relative shift everywhere, set the rc parameter:

    import matplotlib
    matplotlib.rc('axes.formatter', useoffset=False)
    
    0 讨论(0)
  • 2020-11-22 16:22
    plot([1000, 1001, 1002], [1, 2, 3])
    gca().get_xaxis().get_major_formatter().set_useOffset(False)
    draw()
    

    This grabs the current axes, gets the x-axis axis object and then the major formatter object and sets useOffset to false (doc).

    In newer versions (1.4+) of matplotlib the default behavior can be changed via the axes.formatter.useoffset rcparam.

    0 讨论(0)
提交回复
热议问题