我想知道我是否在单个图形上有烛台,ema,sma,如何添加显示日期的蜡烛值(高,低,开盘,收盘价)和该日期的sema的悬停工具?] >
示例代码:
import numpy as np import pandas as pd from bokeh.io import show from bokeh.plotting import figure from bokeh.models import ColumnDataSource df=pd.read_excel(x1) ##x is a dataset consisting date,high,close,low,open,ema5,ema20 df['mid']=df.apply(lambda x:(x['open']+x['close'])/2,axis=1) df['height']=df.apply(lambda x:abs(x['close']-x['open'] if x['close']!=x['open'] else 0.001),axis=1) inc = df.close > df.open dec = df.open > df.close increase=ColumnDataSource(ColumnDataSource.from_df(df.loc[inc])) decrease=ColumnDataSource(ColumnDataSource.from_df(df.loc[dec])) seqs=np.arange(df.shape[0]) df["seq"]=pd.Series(seqs) TOOLS = "xpan,crosshair,zoom_in, zoom_out,box_zoom,pan,reset,xwheel_zoom" p = figure( x_axis_type='linear', active_scroll='xwheel_zoom',active_drag='xpan',tools=TOOLS, plot_width=1375, plot_height= 350,title = 'trading indicators',y_axis_label='Price_15mins') p.xaxis.major_label_overrides = { i: date.strftime("%m/%d/%Y, %H:%M:%S") for i, date in enumerate((copy_df["date"])) } p.segment(df.seq[inc], df.high[inc], df.seq[inc], df.low[inc], color="green") p.segment(df.seq[dec], df.high[dec], df.seq[dec], df.low[dec], color="red") p.rect(x='seq', y='mid', height='height', width=0.3, fill_color='green',line_color="green", source=increase) p.rect(x='seq', y='mid',height='height',width=0.3, fill_color="red", line_color="red", source=decrease) p.line(df.seq,df['EMA5'], color='green',alpha=0.7,muted_color='green', muted_alpha=0.1, legend_label="EMA5") p.line(df.seq,df['EMA20'], color='red',alpha=0.7,muted_color='red', muted_alpha=0.1, legend_label="EMA20") show(p)
[我在这里需要一个悬停显示,在悬停时我可以在x轴上同时看到特定日期的高,低,打开,关闭,ema5,ema20,类似于图中的Sample image。
我想知道单个图形上是否有烛台,ema,sma,如何添加显示日期的蜡烛值(高,低,开盘,收盘价)和该日期的sema的悬浮工具?示例...
使用Google "bokeh hover"
我找到了tools_hover_tooltip_formatting.py并基于它创建了