コード例 #1
0
ファイル: drawk.py プロジェクト: alading241/drawk
    def plot(self,
             area=['V', 'M'],
             width=1000,
             height=680,
             klines=[],
             vlines=[]) -> Grid:
        '''
        @params:
        - area : list   #显示区域
                       'V'   交易量
                       'M'   k线+MACD
                       FieldName: string   Dataframe中的字段名
                       [Field1,Field2,...] Dataframe中的字段名列表,将显示在一个区域
          width: int   #图表宽度 px
          height:int   #图表高度 px
          klines:str   #K线区域显示的数据,Dataframe中的字段名,如MA...
          vline: str   #Volume区域显示的数据,Dataframe中的字段名,如MA...
        - sample:
           chart=data.plot(area=[['small_pct','medium_pct','big_pct','super_pct'],'V','cci'],vlines=['vMA5','vMA10'],klines=['MA5','MA10'])  
        '''
        self.klines = klines
        self.vlines = vlines
        grid = (Grid(init_opts=opts.InitOpts(
            width=str(width) + "px",
            height=str(height) + "px",
            animation_opts=opts.AnimationOpts(animation=False),
        )))
        c = self.K()
        iTop = 10
        iButton = 10
        iWindows = len(area)
        iStep = 0
        if iWindows == 0:
            grid.add(c,
                     grid_opts=opts.GridOpts(pos_top="2%", pos_bottom="10%"))
        elif iWindows > 1:
            grid.add(c,
                     grid_opts=opts.GridOpts(pos_top="2%", pos_bottom="50%"))
            iStep = int(30 / iWindows)
            iButton = 50
        else:
            grid.add(c,
                     grid_opts=opts.GridOpts(pos_top="1%", pos_bottom="30%"))
            iStep = 15
            iButton = 70
        icount = 0
        for w in area:
            #print(iStep)
            if type(w) == list:
                window = Line().add_xaxis(self.dateindex)
                for l in w:
                    window.add_yaxis(
                        series_name=l,
                        y_axis=round(self.data[l],
                                     self.precision).values.tolist(),
                        is_smooth=True,
                        is_symbol_show=False,
                        is_hover_animation=False,
                        label_opts=opts.LabelOpts(is_show=False),
                        linestyle_opts=opts.LineStyleOpts(type_='solid',
                                                          width=2))
                window.axislabel_opts = opts.LabelOpts(is_show=False),
                window.set_global_opts(
                    datazoom_opts=[opts.DataZoomOpts()],
                    xaxis_opts=opts.AxisOpts(
                        type_="category",
                        axislabel_opts=opts.LabelOpts(is_show=False),
                    ),
                    legend_opts=opts.LegendOpts(orient='vertical',
                                                pos_left="top",
                                                pos_top=str(iButton) + "%"),
                )

            elif w == 'V':
                window = self.V()
                #grid.add(v,grid_opts=opts.GridOpts(pos_top= str(iButton)+'%',height=str(iStep)+'%'))
            elif w == 'M':
                window = self.MACD()
                #grid.add(macd,grid_opts=opts.GridOpts(pos_top= str(iButton)+'%',height=str(iStep)+'%'))
            else:
                window = Line().add_xaxis(self.dateindex)
                window.add_yaxis(
                    series_name=w,
                    y_axis=round(self.data[w], self.precision).values.tolist(),
                    is_smooth=True,
                    is_symbol_show=False,
                    is_hover_animation=False,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(type_='solid', width=2))
                window.axislabel_opts = opts.LabelOpts(is_show=True),
                window.set_global_opts(
                    datazoom_opts=[opts.DataZoomOpts()],
                    xaxis_opts=opts.AxisOpts(
                        type_="category",
                        axislabel_opts=opts.LabelOpts(is_show=False),
                    ),
                    legend_opts=opts.LegendOpts(orient='horizontal',
                                                pos_left=str(icount + 20) +
                                                "%"),
                )
                if '_' + w + '_flag' in self.data.columns:
                    #print("find_flag")
                    v1 = self.data[self.data['_' + w + '_flag'] ==
                                   True].index.strftime("%Y-%m-%d").tolist()
                    v2 = self.data[self.data['_' + w + '_flag'] == True][w]
                    c_flag = (EffectScatter().add_xaxis(v1).add_yaxis("", v2))
                    window.overlap(c_flag)
                #grid.add(vLine,grid_opts=opts.GridOpts(pos_top= str(iButton)+'%',height=str(iStep)+'%'))
            icount += 1
            #最后一行加上x刻度
            if icount == iWindows:
                window.options['xAxis'][0]['axisLabel'].opts['show'] = True
            grid.add(window,
                     grid_opts=opts.GridOpts(pos_top=str(iButton) + '%',
                                             height=str(iStep) + '%'))
            iButton = iButton + iStep
        #grid.grid_opts=opts.GridOpts(pos_left="8%", pos_right="8%", height="50%"),
        grid.options['dataZoom'][0].opts['xAxisIndex'] = list(
            range(0, iWindows + 1))
        return grid
コード例 #2
0
ファイル: drawk.py プロジェクト: luckfu/drawk
             is_hover_animation=False,
             label_opts=opts.LabelOpts(is_show=False),
             linestyle_opts= opts.LineStyleOpts(type_='solid',width=2)
         )
         #print('_'+ str(l)+'_flag')
         if '_'+ l+'_flag' in self.data.columns:
             print("    find_flag: %s" % '_'+ l+'_flag')
             xx = self.data[self.data['_'+ l+'_flag']==True].index.strftime("%Y-%m-%d").tolist()
             yy = self.data[self.data['_'+ l+'_flag']==True][l]
             c_flag = (
                 EffectScatter()
                 .add_xaxis(xx)
                 .add_yaxis("",round(yy,self.precision))
             )
             window.overlap(c_flag)
     window.axislabel_opts=opts.LabelOpts(is_show=False),
     window.set_global_opts(datazoom_opts=[opts.DataZoomOpts()],
                 xaxis_opts=opts.AxisOpts(
                     type_="category",
                     axislabel_opts=opts.LabelOpts(is_show=False),
                 ),
                 legend_opts=opts.LegendOpts(orient='vertical',pos_left="top",pos_top=str(iButton)+"%"),
     )
 
                                
 elif w=='V':
     window=self.V()
     #grid.add(v,grid_opts=opts.GridOpts(pos_top= str(iButton)+'%',height=str(iStep)+'%'))                
 elif w=='M':
     window=self.MACD()
     #grid.add(macd,grid_opts=opts.GridOpts(pos_top= str(iButton)+'%',height=str(iStep)+'%'))