from bokeh.models import LinearAxis, Range1d
from bokeh.plotting import figure, show
from bokeh.layouts import row, column
from bokeh.layouts import gridplot
import pandas as pd
import tushare as ts
# 初始化pro接口
pro = ts.pro_api('')
print("获取股票数据.")
example01 = pro.daily(ts_code='000006.SZ', start_date='20190101', end_date='20190301')
# print(example01)
print(type(example01))
example01['date'] = pd.to_datetime(example01['trade_date'])
print(example01['date'])
example01_max = max(example01['high'].tolist())
example01_min = min(example01['low'].tolist())
# 设置条件
inc01 = example01.close > example01.open
dec01 = example01.open > example01.close
print(example01)
w = 12 * 60 * 60 * 1000
bond_code = '123120'
stock_code = '300263'
TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
# 通过传入exmple01de min,max控制figure的展示
p = figure(x_axis_type="datetime", tools=TOOLS,
y_range=(example01_min, example01_max),
width=500, title="{}+{}".format(bond_code, stock_code))
p.xaxis.major_label_orientation = 3.14 / 4
p.grid.grid_line_alpha = 0.3
p.segment(example01.date, example01.high, example01.date, example01.low, color="black")
p.vbar(example01.date[inc01], w, example01.open[inc01], example01.close[inc01],
fill_color="red",
line_color="black")
p.vbar(example01.date[dec01], w, example01.open[dec01], example01.close[dec01],
fill_color="green",
line_color="black")
show(p)
[032量化交易] python互交式显示 bokeh绘制K线图
最新推荐文章于 2024-02-01 15:51:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)