为什么我的Hovertool(来自bokeh)显示不正确的结果?

当我将鼠标悬停在bokeh上时,我在bokeh中的悬停工具显示错误的结果。这是我的代码的一部分,其中包括我定义悬停工具的位置:

headers = ['ticker','size','price','unix','bid','date']
dtypes = {'ticker': 'str','size': 'float','price': 'float','unix': 'float','ask': 'str','date': 'str'}
parse_dates = ['date']
btcnow = pd.read_csv('new 1031-113.csv',header=None,names=headers,dtype=dtypes,parse_dates=parse_dates)
#btc105=pd.read_excel('11-3-11-5 data.xlsx',sheet_name="Sheet1",header=None)
#btc103=btc103.append(btc105,ignore_index = True)
now3 = pd.DataFrame(btcnow,columns=['size','date'])
now4 = pd.DataFrame(btcnow,columns=['date','size'])
x1 = now3.loc[now3["size"] == 31,"date"]
y1 = now3.loc[now3["size"] == 31,"size"]
z1= now4.loc[now4["size"] == 31,"date"]
w1=now4.loc[now4["size"] == 31,"price"]
hover = HoverTool(tooltips=[('index',"$index"),("Date","@date_time{%Y-%m-%d %H:%M:%S.%f}"),("(x1,y1)","(@x1,@y1)"),("(z1,w1)","(@z1,@w1)"),])

我希望能够将数据悬停在数据上并查看日期和时间,但是它却向我显示了Unix时间,我该如何解决? 这是我的数据的一部分:data

zhouzombie 回答:为什么我的Hovertool(来自bokeh)显示不正确的结果?

这不是在显示错误的结果,而是在显示正确的结果,其格式与所需的格式不同。格式化悬停工具提示为covered in the documentation。您需要通过配置悬停工具的formatters属性,告诉Bokeh您想要使用日期时间格式器的任何字段的日期时间格式器:

formatters={
    '@date_time' : 'datetime',# use 'datetime' formatter for 'date_time' field
}
本文链接:https://www.f2er.com/3150406.html

大家都在问