首页 > 解决方案 > 使用 Bokeh Python 未显示烛台

问题描述

我正在尝试运行以下代码来显示我的数据框的烛台模式。

from bokeh.plotting import figure, show, output_file

from math import pi

inc = df.close > df.open
dec = df.open > df.close
w = 12*60*60*1000 # half day in ms

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, title = "MSFT Candlestick")
p.xaxis.major_label_orientation = pi/4
p.grid.grid_line_alpha=0.3

p.segment(df.index, high, df.index, low, color="black")
p.vbar(df.index[inc], w, df.open[inc], df.close[inc], fill_color="#D5E1DD", line_color="black")
p.vbar(df.index[dec], w, df.open[dec], df.close[dec], fill_color="#F2583E", line_color="black")

#output_file("candlestick.html", title="candlestick.py example")

show(p)  # open a browser

我在输出中没有得到任何东西。请让我知道我错过了什么,以便我改进。

标签: pythonpython-3.xplotbokeh

解决方案


看来您使用的代码几乎与Bokeh 示例中的代码完全相同。如果您运行该示例,它将毫无问题地打开。不幸的是,在您粘贴的代码中dfhighlow没有定义,如果没有这些,我无法为您提供太多帮助。


推荐阅读