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)

在这里插入图片描述

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐