gpt4 book ai didi

python - Pandas /matplotlib : change tick label format (force plain not scientific)

转载 作者:太空宇宙 更新时间:2023-11-04 03:35:09 25 4
gpt4 key购买 nike

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

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 轴子图上绘制列

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)

pandas plot

我想以 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)

关闭偏移。

关于python - Pandas /matplotlib : change tick label format (force plain not scientific),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29383307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com