用matplotlib绘制指标

时间:2016-12-16 22:21:16

标签: matplotlib

我将另一种语言的指标重写为Python,但我的情节看起来并不合适。这是图片应该如何看起来像 enter image description here

但我的情节看起来像这样

enter image description here

我的指标底部出了点问题,但我不知道如何修复它。我的完整代码为herehere是我正在使用的data.csv文件。

def matrixSeries(matrix):

    nn = 10  #Smoother
    # --Sup/Res Detail
    SupResPeriod = 50
    SupResPercentage  = 100
    PricePeriod = 16
    ob = 200 #Overbought
    os = -200 #Oversold 
    #OBOS = false
    #dynamic = true
    high = np.array(r['max'])
    low = np.array(r['min'])
    close = np.array(r['close'])
    ys1 = (high + low + close * 2 ) / 4
        rk3 = ta.EMA(ys1, nn) 
    rk4 = ta.STDDEV(ys1, nn)
        rk5 = (ys1 - rk3) * 200 /rk4
    rk6 = ta.EMA(rk5, nn)
    up = ta.EMA(rk6, nn)
    down = ta.EMA(up, nn)

    # remove nans in array
    upNans = np.isnan(up)
    up[upNans] = 0 
    downNans = np.isnan(down)
    down[downNans] = 0 

    Oo = np.where(up<down, up, down)    
    Cc= np.where(up<down, down, up )

    #color
    if matrix == 'color':

        color = []
        aa = Oo > Cc
        bb = up > down 
        color = np.where( aa , 'red' , np.where(bb, 'green','red')  )
        return color

    #Body Calculations
    bodyHigh = np.where(up>down, up, down) 
    bodyLow = np.where(Oo<down, up, down)

    bodyCover = np.where( np.any(up>0) and np.any(down>0), bodyLow, np.where( np.any(up<0) and np.any(down<0), bodyHigh,0))
    bodyCover = bodyCover   
    if matrix == 'cover':
        return bodyCover
    if matrix == 'top':
        return Oo
    if matrix == 'bottom':
        return Cc


ax3 = plt.subplot2grid((6,4), (0,0),sharex=ax1, rowspan=2, colspan=4) 
ax3.bar(r['date'], matrixSeries('top'),  width=1.1,linewidth=0, color=matrixSeries('color'))
ax3.bar(r['date'], matrixSeries('bottom'),  width=1.1,linewidth=0, color=matrixSeries('color'))
ax3.bar(r['date'], matrixSeries('cover'), width=1.1, linewidth=0, color='black' )
ax2.axes.xaxis.set_ticklabels([])
plt.show()

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。 bodyCover计算错误。

#Body Calculations
bodyLow = np.where(up>down, up, down).clip(max=0)
bodyHigh = np.where(Oo<down, up, down).clip(min=0)
bodyCover = bodyLow + bodyHigh

enter image description here

相关问题