Skip to content

Commit f9214b4

Browse files
committed
feat(draw): 为 evplot 和 cnplot 函数增加颜色和透明度参数
- 在 evplot 和 cnplot 函数中添加 upcolor、downcolor 和 alpha 参数 - 使用这些参数来设置有效和无效区域的颜色和透明度 - 提高了图表的可定制性和可视化效果
1 parent 406bb5b commit f9214b4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

hikyuu/draw/drawplot/matplotlib_draw.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,16 @@ def sgplot(sg, new=True, axes=None, style=1, kdata=None):
689689
)
690690

691691

692-
def evplot(ev, ref_kdata, new=True, axes=None):
692+
def evplot(ev, ref_kdata, new=True, axes=None, upcolor='red', downcolor='blue', alpha=0.2):
693693
"""绘制市场有效判断
694694
695695
:param EnvironmentBase cn: 系统有效条件
696696
:param KData ref_kdata: 用于日期参考
697697
:param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
698698
:param axes: 指定在那个轴对象中进行绘制
699+
:param upcolor: 有效时的颜色
700+
:param downcolor: 无效时的颜色
701+
:param alpha: 透明度
699702
"""
700703
refdates = ref_kdata.get_datetime_list()
701704
if axes is None:
@@ -709,18 +712,21 @@ def evplot(ev, ref_kdata, new=True, axes=None):
709712
x = np.array([i for i in range(len(refdates))])
710713
y1 = np.array([1 if ev.is_valid(d) else -1 for d in refdates])
711714
y2 = np.array([-1 if ev.is_valid(d) else 1 for d in refdates])
712-
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor='blue', alpha=0.6)
713-
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor='red', alpha=0.6)
715+
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=downcolor, alpha=alpha)
716+
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=upcolor, alpha=alpha)
714717

715718

716-
def cnplot(cn, new=True, axes=None, kdata=None):
719+
def cnplot(cn, new=True, axes=None, kdata=None, upcolor='red', downcolor='blue', alpha=0.2):
717720
"""绘制系统有效条件
718721
719722
:param ConditionBase cn: 系统有效条件
720723
:param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
721724
:param axes: 指定在那个轴对象中进行绘制
722725
:param KData kdata: 指定的KData,如该值为None,则认为该系统有效条件已经
723726
指定了交易对象,否则,使用该参数作为交易对象
727+
:param upcolor: 有效数时的颜色
728+
:param downcolor: 无效时的颜色
729+
:param alpha: 透明度
724730
"""
725731
if kdata is None:
726732
kdata = cn.to
@@ -739,8 +745,8 @@ def cnplot(cn, new=True, axes=None, kdata=None):
739745
x = np.array([i for i in range(len(refdates))])
740746
y1 = np.array([1 if cn.is_valid(d) else -1 for d in refdates])
741747
y2 = np.array([-1 if cn.is_valid(d) else 1 for d in refdates])
742-
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor='blue', alpha=0.6)
743-
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor='red', alpha=0.6)
748+
axes.fill_between(x, y1, y2, where=y2 > y1, facecolor=downcolor, alpha=alpha)
749+
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor=upcolor, alpha=alpha)
744750

745751

746752
def sysplot(sys, new=True, axes=None, style=1, only_draw_close=False):

0 commit comments

Comments
 (0)