def plotVolume(p, df, plotwidth=800, upcolor='green',
downcolor='red', colname='volume'):
candleWidth = (df.iloc[2]['date'].timestamp() -
df.iloc[1]['date'].timestamp()) * plotwidth
# create new y axis for volume
p.extra_y_ranges = {colname: Range1d(start=min(df[colname].values),
end=max(df[colname].values))}
p.add_layout(LinearAxis(y_range_name=colname), 'right')
# Plot green candles
inc = df.close > df.open
p.vbar(x=df.date[inc],
width=candleWidth,
top=df[colname][inc],
bottom=0,
alpha=0.1,
fill_color=upcolor,
line_color=upcolor,
y_range_name=colname)
# Plot red candles
dec = df.open > df.close
p.vbar(x=df.date[dec],
width=candleWidth,
top=df[colname][dec],
bottom=0,
alpha=0.1,
fill_color=downcolor,
line_color=downcolor,
y_range_name=colname)
评论列表
文章目录