Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41922159
czsc
提交
e43c6555
C
czsc
项目概览
weixin_41922159
/
czsc
与 Fork 源项目一致
Fork自
zengbin93 / czsc
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
czsc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e43c6555
编写于
9月 27, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.6 新增plot
上级
53f438b7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
4 deletion
+92
-4
czsc/plot.py
czsc/plot.py
+60
-0
requirements.txt
requirements.txt
+4
-4
test/test_plot.py
test/test_plot.py
+28
-0
未找到文件。
czsc/plot.py
0 → 100644
浏览文件 @
e43c6555
# coding: utf-8
"""
使用 pyecharts 定制绘图模块
"""
from
pyecharts
import
options
as
opts
from
pyecharts.charts
import
HeatMap
,
Grid
from
pyecharts.options
import
HeatMapItem
from
typing
import
List
,
Callable
def
heat_map
(
data
:
List
[
dict
],
x_label
:
List
[
str
]
=
None
,
y_label
:
List
[
str
]
=
None
,
title
:
str
=
"热力图"
,
width
:
str
=
"900px"
,
height
:
str
=
"680px"
)
->
HeatMap
:
"""绘制热力图
:param data: 用于绘制热力图的数据,示例如下
[{'x': '0hour', 'y': '0day', 'heat': 11},
{'x': '0hour', 'y': '1day', 'heat': 40},
{'x': '0hour', 'y': '2day', 'heat': 38},
{'x': '0hour', 'y': '3day', 'heat': 36},
{'x': '0hour', 'y': '4day', 'heat': 11}]
:param x_label: x轴标签
:param y_label: y轴标签
:param title: 图表标题
:param width: 图表宽度
:param height: 图表高度
:return: 图表
"""
value
=
[
HeatMapItem
(
value
=
[
s
[
'x'
],
s
[
'y'
],
s
[
'heat'
]])
for
s
in
data
]
heat
=
[
s
[
'heat'
]
for
s
in
data
]
if
not
x_label
:
x_label
=
sorted
(
list
(
set
([
s
[
'x'
]
for
s
in
data
])))
if
not
y_label
:
y_label
=
sorted
(
list
(
set
([
s
[
'y'
]
for
s
in
data
])))
vis_map_opts
=
opts
.
VisualMapOpts
(
pos_left
=
"90%"
,
pos_top
=
"20%"
,
min_
=
min
(
heat
),
max_
=
max
(
heat
))
title_opts
=
opts
.
TitleOpts
(
title
=
title
)
init_opts
=
opts
.
InitOpts
(
page_title
=
title
,
width
=
width
,
height
=
height
)
dz_inside
=
opts
.
DataZoomOpts
(
False
,
"inside"
,
xaxis_index
=
[
0
],
range_start
=
80
,
range_end
=
100
)
dz_slider
=
opts
.
DataZoomOpts
(
True
,
"slider"
,
xaxis_index
=
[
0
],
pos_top
=
"96%"
,
pos_bottom
=
"0%"
,
range_start
=
80
,
range_end
=
100
)
legend_opts
=
opts
.
LegendOpts
(
is_show
=
False
)
hm
=
HeatMap
(
init_opts
=
init_opts
)
hm
.
add_xaxis
(
x_label
)
hm
.
add_yaxis
(
"heat"
,
y_label
,
value
,
label_opts
=
opts
.
LabelOpts
(
is_show
=
True
,
position
=
"inside"
))
hm
.
set_global_opts
(
title_opts
=
title_opts
,
visualmap_opts
=
vis_map_opts
,
legend_opts
=
legend_opts
,
xaxis_opts
=
opts
.
AxisOpts
(
grid_index
=
0
),
datazoom_opts
=
[
dz_inside
,
dz_slider
])
return
hm
requirements.txt
浏览文件 @
e43c6555
requests
~=2.23.0
pyecharts
~
=1.8.1
pyecharts
>
=1.8.1
mplfinance
~=0.12.4a0
tqdm
pandas
>=1.1.0
tushare
~=1.2.5
0
tushare
>=1.2.6
0
matplotlib
~=3.0.3
zb
>=0.0.14
numpy
~=1.16.2
numba
~=0.43.1
\ No newline at end of file
numpy
>=1.16.2
numba
>=0.43.1
\ No newline at end of file
test/test_plot.py
0 → 100644
浏览文件 @
e43c6555
# coding: utf-8
import
sys
import
warnings
sys
.
path
.
insert
(
0
,
'.'
)
sys
.
path
.
insert
(
0
,
'..'
)
import
os
import
numpy
as
np
import
pandas
as
pd
import
random
import
czsc
from
czsc
import
plot
warnings
.
warn
(
"czsc version is {}"
.
format
(
czsc
.
__version__
))
# cur_path = os.path.split(os.path.realpath(__file__))[0]
cur_path
=
"./test"
def
test_heat_map
():
data
=
[{
"x"
:
"{}hour"
.
format
(
i
),
"y"
:
"{}day"
.
format
(
j
),
"heat"
:
random
.
randint
(
0
,
50
)}
for
i
in
range
(
24
)
for
j
in
range
(
7
)]
x_label
=
[
"{}hour"
.
format
(
i
)
for
i
in
range
(
24
)]
y_label
=
[
"{}day"
.
format
(
i
)
for
i
in
range
(
7
)]
hm
=
plot
.
heat_map
(
data
,
x_label
=
x_label
,
y_label
=
y_label
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录