Skip to content

Commit

Permalink
add matplot ev.plot
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Feb 3, 2024
1 parent 7896300 commit 99983fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion hikyuu/draw/drawplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# 1. 20171122, Added by fasiondog
# ===============================================================================

from hikyuu.core import KData, Indicator, SignalBase, ConditionBase, System
from hikyuu.core import KData, Indicator, SignalBase, ConditionBase, EnvironmentBase, System

import matplotlib
from matplotlib.pylab import gca as mpl_gca
Expand All @@ -42,6 +42,7 @@
from .matplotlib_draw import ibar as mpl_ibar
from .matplotlib_draw import sgplot as mpl_sgplot
from .matplotlib_draw import cnplot as mpl_cnplot
from .matplotlib_draw import evplot as mpl_evplot
from .matplotlib_draw import sysplot as mpl_sysplot
from .matplotlib_draw import ax_draw_macd as mpl_ax_draw_macd
from .matplotlib_draw import ax_draw_macd2 as mpl_ax_draw_macd2
Expand Down Expand Up @@ -117,6 +118,8 @@ def use_draw_with_matplotlib():
Indicator.bar = mpl_ibar

SignalBase.plot = mpl_sgplot

EnvironmentBase.plot = mpl_evplot
ConditionBase.plot = mpl_cnplot

System.plot = mpl_sysplot
Expand Down
26 changes: 24 additions & 2 deletions hikyuu/draw/drawplot/matplotlib_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,30 @@ def sgplot(sg, new=True, axes=None, style=1, kdata=None):
)
def evplot(ev, ref_kdata, new=True, axes=None):
"""绘制市场有效判断

:param EnvironmentBase cn: 系统有效条件
:param KData ref_kdata: 用于日期参考
:param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
:param axes: 指定在那个轴对象中进行绘制
"""
refdates = ref_kdata.get_datetime_list()
if axes is None:
if new:
axes = create_figure(2)
kplot(ref_kdata, axes=axes[0])
axes = axes[1]
else:
axes = gca()
x = np.array([i for i in range(len(refdates))])
y1 = np.array([1 if ev.is_valid(d) else -1 for d in refdates])
y2 = np.array([-1 if ev.is_valid(d) else 1 for d in refdates])
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor='blue', alpha=0.6)
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor='red', alpha=0.6)
def cnplot(cn, new=True, axes=None, kdata=None):
"""绘制系统有效条件

Expand All @@ -634,8 +658,6 @@ def cnplot(cn, new=True, axes=None, kdata=None):
cn.to = kdata
refdates = kdata.get_datetime_list()
date_index = dict([(d, i) for i, d in enumerate(refdates)])
if axes is None:
if new:
axes = create_figure(2)
Expand Down

0 comments on commit 99983fa

Please sign in to comment.