Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
0533a68b
C
czsc
项目概览
zengbin93
/
czsc
通知
23
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
czsc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0533a68b
编写于
6月 01, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.3.4 新增基于 matplotlib 的结果绘制
上级
3b9affee
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
0 deletion
+59
-0
chan/utils.py
chan/utils.py
+59
-0
未找到文件。
chan/utils.py
浏览文件 @
0533a68b
...
...
@@ -4,6 +4,9 @@ import pandas as pd
from
pyecharts
import
options
as
opts
from
pyecharts.commons.utils
import
JsCode
from
pyecharts.charts
import
Kline
,
Line
,
Bar
,
Grid
,
Scatter
import
mplfinance
as
mpf
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
from
.ta
import
macd
...
...
@@ -258,3 +261,59 @@ def plot_kline(ka, bs=None, file_html="chan.html", width="1400px", height="680px
grid_opts
=
opts
.
GridOpts
(
pos_left
=
"3%"
,
pos_right
=
"1%"
,
pos_top
=
"82%"
,
height
=
"14%"
),
)
grid_chart
.
render
(
path
=
file_html
)
def
plot_ka
(
ka
,
file_image
,
mav
=
(
5
,
20
,
120
,
250
),
max_k_count
=
1000
):
"""绘制 ka,保存到 file_image"""
df
=
pd
.
DataFrame
(
ka
.
kline
)
df
.
rename
({
"open"
:
"Open"
,
"close"
:
"Close"
,
"high"
:
"High"
,
"low"
:
"Low"
,
"vol"
:
"Volume"
},
axis
=
1
,
inplace
=
True
)
df
.
index
=
pd
.
to_datetime
(
df
[
'dt'
])
df
=
df
.
tail
(
max_k_count
)
kwargs
=
dict
(
type
=
'candle'
,
mav
=
mav
,
volume
=
True
)
bi_xd
=
[
[(
x
[
'dt'
],
x
[
'bi'
])
for
_
,
x
in
df
.
iterrows
()
if
x
[
'bi'
]
>
0
],
[(
x
[
'dt'
],
x
[
'xd'
])
for
_
,
x
in
df
.
iterrows
()
if
x
[
'xd'
]
>
0
]
]
mc
=
mpf
.
make_marketcolors
(
up
=
'red'
,
down
=
'green'
,
edge
=
'i'
,
wick
=
'i'
,
volume
=
'in'
,
inherit
=
True
)
s
=
mpf
.
make_mpf_style
(
gridaxis
=
'both'
,
gridstyle
=
'-.'
,
y_on_right
=
False
,
marketcolors
=
mc
)
mpl
.
rcParams
[
'font.sans-serif'
]
=
[
'KaiTi'
]
mpl
.
rcParams
[
'font.serif'
]
=
[
'KaiTi'
]
mpl
.
rcParams
[
'font.size'
]
=
48
mpl
.
rcParams
[
'axes.unicode_minus'
]
=
False
mpl
.
rcParams
[
'lines.linewidth'
]
=
1.0
title
=
'%s缠论分析结果(%s - %s)'
%
(
ka
.
symbol
,
df
.
index
[
0
].
__str__
(),
df
.
index
[
-
1
].
__str__
())
fig
,
axes
=
mpf
.
plot
(
df
,
columns
=
[
'Open'
,
'High'
,
'Low'
,
'Close'
,
'Volume'
],
style
=
s
,
title
=
title
,
ylabel
=
'K线'
,
ylabel_lower
=
'成交量'
,
**
kwargs
,
alines
=
dict
(
alines
=
bi_xd
,
colors
=
[
'r'
,
'g'
],
linewidths
=
8
,
alpha
=
0.35
),
returnfig
=
True
)
if
len
(
df
)
<
1000
:
w
=
len
(
df
)
*
0.2
elif
len
(
df
)
<
2000
:
w
=
len
(
df
)
*
0.1
elif
len
(
df
)
<
5000
:
w
=
len
(
df
)
*
0.04
else
:
w
=
len
(
df
)
*
0.02
fig
.
set_size_inches
(
w
,
30
)
ax
=
plt
.
gca
()
ax
.
set_xbound
(
-
1
,
len
(
df
)
+
1
)
fig
.
savefig
(
fname
=
file_image
,
dpi
=
50
,
bbox_inches
=
'tight'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录