Reputation: 31
I want to add markers to my Bokeh chart, here's my sample code, signals table has positions column which has values 1 and 0, if positions==1 I need to add marker to my TimeSeries chart. How do I do this without using legacy matplotlib plotting, but just using Bokeh interface?
def bokeh_chart(symbol, bars, signals, returns):
xyvalues = pd.DataFrame({
"Price": bars['Close'],
"Date": bars.index.values,
"short_mavg": signals['short_mavg'],
"long_mavg": signals['long_mavg']})
pt = TimeSeries(xyvalues, index='Date', legend=True,
title=symbol , ylabel='Stock Prices', width=400, height=200)
#for Scatter, is it possible to be have a dataframe for x and y parameter (1st and 2nd parameters in the function below)?
p = Scatter(signals, signals.ix[signals.positions == 1.0].index, signals.short_mavg[signals.positions == 1.0], marker='triangle')
script,div=components(p)
return {"script":script, "div":div}
Upvotes: 3
Views: 891
Reputation: 2416
To combine the charts timeseries with a scatter, a solution that worked for me (using Bokeh 0.11.1) is to use basic glyphs instead of charts. In your example you would use the argument of figure
x_axis_type="datetime"
and the basic glyph line
instead of the chart TimeSeries
, and use the glyph triangle
instead of the chart Scatter
.
from bokeh.plotting import figure
p = figure(title="My title", width=400, height=200,
x_axis_type="datetime")
p.yaxis.axis_label = "Stock Prices"
p.yaxis.axis_label = "Date"
p.triangle(xyvalues['Date'], xyvalues['short_mavg'], legend="short")
p.line(xyvalues['Date'], xyvalues['Price'], legend="price")
I hope it also helps in your case.
Upvotes: 1