pandas / matplotlib:更改刻度标签格式(力平原不科学)

pandas / matplotlib: change tick label format (force plain not scientific)

我有一个包含 2 列的 pandas dataframe,格式如下:

df.head()
                            column1  column2
time                                                                        
1900-01-01 12:30:05.089883  19042.5  19042.8615   
1900-01-01 12:30:05.210055  19042.5  19042.8615   
1900-01-01 12:30:05.290165  19042.5  19042.8615   
1900-01-01 12:30:05.449856  19042.5  19042.8615   

我在同一个 matplotlib axes subplot

上绘制列
def plot(df):
    ax = df.plot(y='column1', figsize=(20, 8))
    df.plot(y='column2', ax=ax)

    # this doesn't make a difference
    ax.ticklabel_format(style='plain', axis='y')    

    mpl.pyplot.show()

plot(df)

我想以 plain 格式打印 y 轴 - 如何强制它停止使用 scientific

也就是说,y 轴从 06,并且有一个额外的标签 1.9037e4。我希望它从 1903719043

我已经试过了,但没什么区别:

ax.ticklabel_format(style='plain', axis='y') 

来自docs

To reduce the chances that the ticklabels overlap the ticks are labeled as deltas from a fixed offset. For example:

ax.plot(np.arange(2000, 2010), range(10))

will have tick of 0-9 with an offset of +2e3. If this is not desired turn off the use of the offset on the default formatter:

ax.get_xaxis().get_major_formatter().set_useOffset(False)

set the rcParam axes.formatter.useoffset=False to turn it off globally, or set a different formatter.

所以,你可以写

 ax.get_yaxis().get_major_formatter().set_useOffset(False)

关闭偏移。