plotly基于dataframe数据绘制股票K线图并添加技术指标
# 添加均线数据;
import plotly as py # 导入plotly库并命名为py
import plotly.graph_objs as go
import pandas as pd
fig = go.Figure()
# -------------pre def
pyplt = py.offline.plot
df = pd.read_csv(r'dat/appl.csv', index_col=['date'], parse_dates=['date'])
df['avg_5'] = df['close'].rolling(5).mean()
# K线图
trace = go.Candlestick(
x=df.index,
open=df.open,
high=df.high,
low=df.low,
close=df.close,
)
# 5日均线拟合直线
add_line = go.Scatter(
x=df.index,
y=df.avg_5,
name= '5日均线',
line=dict(color