Example #1
0
def cnplot(cn, new=True, axes=None, kdata=None):
    """绘制系统有效条件

    :param ConditionBase cn: 系统有效条件
    :param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
    :param axes: 指定在那个轴对象中进行绘制
    :param KData kdata: 指定的KData,如该值为None,则认为该系统有效条件已经
                        指定了交易对象,否则,使用该参数作为交易对象
    """
    if kdata is None:
        kdata = cn.getTO()
    else:
        cn.setTO(kdata)

    refdates = kdata.get_date_list()
    date_index = dict([(d, i) for i, d in enumerate(refdates)])

    if axes is None:
        if new:
            axes = create_figure()
            kplot(kdata, axes=axes)
        else:
            axes = gca()

    x = np.array([i for i in range(len(refdates))])
    y1 = np.array([1 if cn.isValid(d) else -1 for d in refdates])
    y2 = np.array([-1 if cn.isValid(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)
Example #2
0
def cnplot(cn, new=True, axes=None, kdata=None):
    """绘制系统有效条件

    :param ConditionBase cn: 系统有效条件
    :param new: 仅在未指定axes的情况下生效,当为True时,创建新的窗口对象并在其中进行绘制
    :param axes: 指定在那个轴对象中进行绘制
    :param KData kdata: 指定的KData,如该值为None,则认为该系统有效条件已经
                        指定了交易对象,否则,使用该参数作为交易对象
    """
    if kdata is None:
        kdata = cn.getTO()
    else:
        cn.setTO(kdata)
        
    refdates = kdata.getDatetimeList()
    date_index = dict([(d,i) for i,d in enumerate(refdates)])
        
    if axes is None:
        if new:
            axes = create_figure()
            kplot(kdata, axes=axes)
        else:
            axes = gca()        

    x = np.array([i for i in range(len(refdates))])
    y1 = np.array([1 if cn.isValid(d) else -1 for d in refdates])
    y2 = np.array([-1 if cn.isValid(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)