提交 e43c6555 编写于 作者: Z zengbin93

0.5.6 新增plot

上级 53f438b7
# 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
requests~=2.23.0
pyecharts~=1.8.1
pyecharts>=1.8.1
mplfinance~=0.12.4a0
tqdm
pandas>=1.1.0
tushare~=1.2.50
tushare>=1.2.60
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
# 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.
先完成此消息的编辑!
想要评论请 注册