其他分享
首页 > 其他分享> > plotly基于dataframe数据绘制股票K线图并添加技术指标

plotly基于dataframe数据绘制股票K线图并添加技术指标

作者:互联网

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

标签:线图,df,py,dataframe,plotly,import,go,close
来源: https://blog.csdn.net/zhongkeyuanchongqing/article/details/119305259