# Python打造五线图谱(乐活五线谱)简单版

python 3.7
scipy==1.1.0
plotly==4.7.1


import pandas as pd
import talib
import os
import chart_studio.plotly  as py
import plotly.graph_objs as go
import plotly.offline as pyoff
import plotly.graph_objs as go
import plotly.io as pio
import pandas as pd
import numpy as np
import plotly
plotly.io.orca.config.executable = '/usr/local/bin/orca'
plotly.io.orca.config.save()
# 线性回归
from sklearn import linear_model
import numpy as np
reg = linear_model.LinearRegression()
#对应序号是 range(len(data))
df['itx'] =[i  for i in range(1,len(list(df['last_close']))+1)]
# x , y
reg.fit (df['itx'].values.reshape(-1, 1),df['last_close'])
#斜率为
print(reg.coef_)
#截距为
print(reg.intercept_)
df['coef'] = reg.coef_[0]
df['intercept'] = reg.intercept_
# y = c+x*b = 截距+x*斜率
#趋势线
df['priceTL'] = df['intercept']+df['itx']*df['coef']
#误差
df['y-TL'] = df['close']-df['priceTL']
# 标准差
df['SD'] = df['y-TL'].std()
# 分别计算上下 1个和2个标准差
df['TL-2SD'] = df['priceTL']-2*df['SD']
df['TL-SD'] = df['priceTL']-df['SD']
df['TL+2SD'] = df['priceTL']+2*df['SD']
df['TL+SD'] = df['priceTL']+df['SD']

import plotly.graph_objects as go

fig = go.Figure()
for i in ['last_close','priceTL','TL-2SD', 'TL-SD',
'TL+SD', 'TL+2SD']:
go.Scatter(
x=df['time_key'],
y=df[i],
name=i
))

fig.update_layout(
xaxis_title="x Axis Title",
yaxis_title="y Axis Title",
font=dict(
family="Courier New, monospace",
size=18,
color="#7f7f7f"
),
title={'text': "Plot Title",'xanchor': 'center','y':0.995,
'x':0.5,
'yanchor': 'top'},
)

fig.show()

09-02 5597

01-13

08-15 6044

03-22 6238

06-14 4693

11-10 2794

04-14 5465

10-12 6613

07-17 3614

05-20 4415

04-15 1万+

01-15 1854

10-08 1485

11-08 6781

04-11 5693

07-01 1637

12-11 1万+

06-19 279

05-15 1万+

#### python简单实战项目：《冰与火之歌1-5》角色关系图谱构建——人物关系可视化

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客