matplotlib yticks中的值错误 [英] Wrong value in matplotlib yticks
问题描述
我正在尝试从pandas数据框进行绘制,而matplotlib在yticks中显示了错误的值
I'm trying to plot from pandas dataframe and matplotlib show wrong value in yticks
高度数据:
2014-08-08 06:00:00 2609.4942014-08-08 05:45:00 2609.5502014-08-08 05:30:00 2609.6052014-08-08 05:15:00 2609.6582014-08-08 05:00:00 2609.7032014-08-08 04:45:00 2609.7412014-08-08 04:30:00 2609.7692014-08-08 04:15:00 2609.7872014-08-08 04:00:00 2609.7992014-08-08 03:45:00 2609.802
代码:
import pandas as pd
df = pd.Dataframe('mydata')
df.plot()
绘制图形的链接:http://bayanbox.ir/id/7161086291332750314?view
我不知道是否必须在yticks中放置"2609.703"之类的值,而不是图形中显示的值
I don't know have to put value like '2609.703' in yticks instead of what shown in graph
推荐答案
它没有显示不正确的刻度,它只是显示相对于偏移值的内容(注意 y 轴顶部的文本).默认情况下,当您显示大数字且它们之间的差异很小时,就会发生这种情况.
It's not showing incorrect ticks, it's just displaying things relative to an offset value (notice the text at the top of the y-axis). By default, this happens whenever you're displaying large number with very little difference between them.
使用 ax.ticklabel_format(...)
.在您的情况下,您要指定 useOffset = False
.
例如:
import matplotlib.pyplot as plt
data = [2609.494, 2609.55, 2609.605, 2609.658, 2609.703,
2609.741, 2609.769, 2609.787, 2609.799, 2609.802]
fig, ax = plt.subplots()
ax.plot(data)
ax.ticklabel_format(useOffset=False)
plt.show()
或者,如果您使用的是熊猫 DataFrame
的 plot
方法,则其返回值是axes对象,所以只需:
Or, if you're using the plot
method of a Pandas DataFrame
, its return value is the axes object, so just:
ax = df.plot()
ax.ticklabel_format(useOffset=False)
这篇关于matplotlib yticks中的值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!