Exemple #1
0
 def plot(self, code=None):
     if code is None:
         data=[]
         axis=[]
         for dates,row in self.data.iterrows():
             open,high,low,close=row[1:5]
             datas=[open,close,low,high]
             axis.append(dates[0])
             data.append(datas)
         path_name='.\QA_'+self.type+'_'+self.code[0]+'_'+self.if_fq+'.html'
         kline=Kline(self.code[0]+'__'+self.if_fq+'__'+self.type,width=1360,height=700)
         kline.add(self.code[0],axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
         kline.render(path_name)
         QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
     else:
         data=[]
         axis=[]
         for dates,row in self.select_code(code).data.iterrows():
             open,high,low,close=row[1:5]
             datas=[open,close,low,high]
             axis.append(dates[0])
             data.append(datas)
         path_name='.\QA_'+self.type+'_'+code+'_'+self.if_fq+'.html'
         kline=Kline(code+'__'+self.if_fq+'__'+self.type,width=1360,height=700)
         kline.add(code,axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
         kline.render(path_name)
         QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
Exemple #2
0
    def create_view():
        # open, close, lowest, highest]
        v1 = []
        kline = Kline("日K线图")
        rows = SQLiteUtil.select_all()
        down_flag = []
        for row in rows:
            down_flag.append(row[0])
            v1.append([row[3], row[4], row[1], row[2]])
        kline.add(
            "日K",
            down_flag,
            v1,
            mark_point=["max"],
            is_datazoom_show=True,
        )
        kline.render(path="../view/day.html")

        v1 = []
        kline = Kline("7天K线图")
        rows = SQLiteUtil.select_group_by_week()
        down_flag = []
        for row in rows:
            down_flag.append(row.get("week_flag"))
            v1.append([
                row.get("first_price"),
                row.get("last_price"),
                row.get("min_price"),
                row.get("max_price")
            ])
        kline.add(
            "周K",
            down_flag,
            v1,
            mark_point=["max"],
            is_datazoom_show=True,
        )
        kline.render(path="../view/week.html")

        v1 = []
        kline = Kline("30天K线图")
        rows = SQLiteUtil.select_group_by_moon()
        down_flag = []
        for row in rows:
            down_flag.append(row.get("moon_flag"))
            v1.append([
                row.get("first_price"),
                row.get("last_price"),
                row.get("min_price"),
                row.get("max_price")
            ])
        kline.add(
            "月K",
            down_flag,
            v1,
            mark_point=["max"],
            is_datazoom_show=True,
        )
        kline.render(path="../view/moon.html")
Exemple #3
0
def test_kline():

    # kline_0
    v1 = [[2320.26, 2320.26, 2287.3,
           2362.94], [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58,
           2440.38], [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1)
    kline.show_config()
    kline.render()

    # kline_1
    kline = Kline("K 线图示例")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1,
              mark_point=["max"],
              is_datazoom_show=True)
    kline.show_config()
    kline.render()

    # kline_2
    kline = Kline("K 线图示例")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1,
              mark_point=["max"],
              is_datazoom_show=True,
              datazoom_orient='vertical')
    kline.show_config()
    kline.render()
Exemple #4
0
    def plot(self, code=None):
        'plot the market_data'
        if code is None:
            path_name = '.' + os.sep + 'QA_' + self.type + \
                '_codepackage_' + self.if_fq + '.html'
            kline = Kline('CodePackage_' + self.if_fq + '_' + self.type,
                          width=1360,
                          height=700,
                          page_title='QUANTAXIS')

            data_splits = self.splits()

            for i_ in range(len(data_splits)):
                data = []
                axis = []
                for dates, row in data_splits[i_].data.iterrows():
                    open, high, low, close = row[1:5]
                    datas = [open, close, low, high]
                    axis.append(dates[0])
                    data.append(datas)

                kline.add(self.code[i_],
                          axis,
                          data,
                          mark_point=["max", "min"],
                          is_datazoom_show=True,
                          datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info('The Pic has been saved to your path: %s' %
                             path_name)
        else:
            data = []
            axis = []
            for dates, row in self.select_code(code).data.iterrows():
                open, high, low, close = row[1:5]
                datas = [open, close, low, high]
                axis.append(dates[0])
                data.append(datas)

            path_name = '.{}QA_{}_{}_{}.html'.format(os.sep, self.type, code,
                                                     self.if_fq)
            kline = Kline('{}__{}__{}'.format(code, self.if_fq, self.type),
                          width=1360,
                          height=700,
                          page_title='QUANTAXIS')
            kline.add(code,
                      axis,
                      data,
                      mark_point=["max", "min"],
                      is_datazoom_show=True,
                      datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info(
                'The Pic has been saved to your path: {}'.format(path_name))
Exemple #5
0
    def __init__(self):

        self.kline = Kline()
        self.kline2 = Kline()
        # 初始化一个指标线
        self.line = Line()
        self.line_long_win = Line()
        self.line_long_loss = Line()
        self.line_short_win = Line()
        self.line_short_loss = Line()
Exemple #6
0
def plot_datastruct(__stock_hq_base, code=None):
    if code is None:
        path_name = '.' + os.sep + 'QA_' + __stock_hq_base.type + \
            '_codepackage_' + __stock_hq_base.if_fq + '.html'
        kline = Kline('CodePackage_' + __stock_hq_base.if_fq + '_' +
                      __stock_hq_base.type,
                      width=1360,
                      height=700,
                      page_title='QUANTAXIS')

        data_splits = __stock_hq_base.splits()

        for i_ in range(len(data_splits)):
            data = []
            axis = []
            for dates, row in data_splits[i_].data.iterrows():
                open, high, low, close = row[1:5]
                datas = [open, close, low, high]
                axis.append(dates[0])
                data.append(datas)

            kline.add(__stock_hq_base.code[i_],
                      axis,
                      data,
                      mark_point=["max", "min"],
                      is_datazoom_show=True,
                      datazoom_orient='horizontal')
        kline.render(path_name)
        webbrowser.open(path_name)
        QA_util_log_info('The Pic has been saved to your path: %s' % path_name)
    else:
        data = []
        axis = []
        for dates, row in __stock_hq_base.select_code(code).data.iterrows():
            open, high, low, close = row[1:5]
            datas = [open, close, low, high]
            axis.append(dates[0])
            data.append(datas)

        path_name = '.' + os.sep + 'QA_' + __stock_hq_base.type + \
            '_' + code + '_' + __stock_hq_base.if_fq + '.html'
        kline = Kline(code + '__' + __stock_hq_base.if_fq + '__' +
                      __stock_hq_base.type,
                      width=1360,
                      height=700,
                      page_title='QUANTAXIS')
        kline.add(code,
                  axis,
                  data,
                  mark_point=["max", "min"],
                  is_datazoom_show=True,
                  datazoom_orient='horizontal')
        kline.render(path_name)
        webbrowser.open(path_name)
        QA_util_log_info('The Pic has been saved to your path: %s' % path_name)
Exemple #7
0
def kxian4_fun():
    from pyecharts import Kline
    api = ts.pro_api(
        'acfe91c33583e4f34c757cfc5360f7e51eefd9f0c259f4204ea4720f')

    # 取000001的前复权行情
    df = ts.pro_bar(pro_api=api,
                    ts_code='000001.SZ',
                    adj='qfq',
                    start_date='20181201',
                    end_date='20181231')
    df = df.sort_index(axis=0)
    df1 = df[['open', 'high', 'open', 'close']]

    v1 = df1.values.tolist()
    kline = Kline("K 线图示例")

    aa = [i for i in df1.index.format()]

    kline.add(
        "日K",
        aa,
        v1,
        mark_point=["max"],
        is_datazoom_show=True,
        datazoom_orient="vertical",
    )
    return kline
Exemple #8
0
 def kline_plot(self,ktype=0):
     df=self.cal_hadata()
     #画K线图数据
     date = df.index.strftime('%Y%m%d').tolist()
     if ktype==0:
         k_value = df[['adjopen','adjclose', 'adjlow','adjhigh']].values
     else:
         k_value = df[['ha_open','ha_close', 'ha_low', 'ha_high']].values
     #引入pyecharts画图使用的是0.5.11版本,新版命令需要重写
     
     kline = Kline(self.name+'行情走势')
     kline.add('日K线图', date, k_value,
           is_datazoom_show=True,is_splitline_show=False)
     #加入5、20日均线
     df['ma20']=df.adjclose.rolling(20).mean()
     df['ma5']=df.adjclose.rolling(5).mean()
     line = Line()
     v0=df['ma5'].round(2).tolist()
     v=df['ma20'].round(2).tolist()
     line.add('5日均线', date,v0,
          is_symbol_show=False,line_width=2)
     line.add('20日均线', date,v, 
          is_symbol_show=False,line_width=2)
     #成交量
     bar = Bar()
     bar.add('成交量', date, df['vol'],tooltip_tragger='axis', 
             is_legend_show=False, is_yaxis_show=False, 
             yaxis_max=5*max(df['vol']))
     overlap = Overlap()
     overlap.add(kline)
     overlap.add(line,)
     overlap.add(bar,yaxis_index=1, is_add_yaxis=True)
     return overlap    
Exemple #9
0
def candLestick_mode():
    v1 = [[2320.26, 2320.26, 2287.3,
           2362.94], [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58,
           2440.38], [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例")
    kline.add("日K", ["2019/1/{}".format(i + 1) for i in range(31)], v1)
    kline.render('kline.html')
Exemple #10
0
def draw(code):
    import pandas as pd
    stock = pd.read_csv(code + '.csv',
                        usecols=[0, 1, 2, 3, 4, 5, 6],
                        encoding='gbk')
    stock.head()

    stock_new = stock.iloc[:180, :]
    stock_new_sorted = stock_new.sort_values('日期', ascending=True)
    stock_new_sorted.head()

    from pyecharts import Kline
    stock_code = stock_new_sorted['股票代码'][0]
    stock_name = stock_new_sorted['名称'][0]
    index = stock_new_sorted['日期']
    v = [[o, close, lowest, highest] for o, close, lowest, highest in zip(
        stock_new_sorted['开盘价'], stock_new_sorted['收盘价'],
        stock_new_sorted['最低价'], stock_new_sorted['最高价'])]
    kline = Kline()
    kline.add(stock_name + '(' + stock_code + ')' + '日K线图',
              index,
              v,
              mark_point=["max"],
              is_datazoom_show=True)
    kline.render()
def drawKline(datadf, tradeRecorddf):
    datadf["datetime"] = datadf["datetime"].dt.strftime("%Y-%m-%d %H:%M:%S")
    OHLC = df[["open", "close", "low", "high"]]
    OHLC = OHLC.values
    DATETIME = df["datetime"].values

    longOrderDF = tradeRecorddf[tradeRecorddf["direction"] == "long position"]
    longOrderDF = longOrderDF[["time", "deal price", "kaiping"]].values
    shortOrderDF = tradeRecorddf[tradeRecorddf["direction"] == "short position"]
    shortOrderDF = shortOrderDF[["time", "deal price", "kaiping"]].values
    markpointlist = []
    for longorders in longOrderDF:
        markpointlist.append(RedArrow(longorders[0], longorders[1], longorders[2]))
    for shortorders in shortOrderDF:
        markpointlist.append(GreenArrow(shortorders[0], shortorders[1], shortorders[2]))

    page = Page()
    grid = Grid(width=1920, height=900)
    kline = Kline("candlestick")
    kline.add("candlestick", DATETIME, OHLC, is_datazoom_show=True, datazoom_type='inside',
              datazoom_range=[90, 100], tooltip_tragger_on='mousemove|click', tooltip_axispointer_type='cross',
              is_label_show=False, mark_point_raw=markpointlist)
    grid.add(kline, grid_top="3%", grid_height="95%")
    page.add(grid)
    now = dt.datetime.now()
    today = now.strftime('%Y%m%d')
    time = now.strftime("%H_%M_%S")
    home = os.environ['HOME']
    page.render(home + "/Pictures/" + today + "/" + "plotKlineChartandSignal" + time + ".html")
Exemple #12
0
def grids(data):
    kline = Kline(data.symbol[0])
    kline.add(
        '',
        data.index,
        data.loc[:, ['open', 'close', 'low', 'high']].values,
        mark_line=['max', 'min'],
        mark_line_valuedim=['highest', 'lowest'],
        is_datazoom_show=True,
        datazoom_xaxis_index=[0, 1],
    )

    turnover = Bar()
    turnover.add(
        '',
        data.index,
        data['turnover'].values / pow(10, 9),
        mark_line=['max', 'min'],
        is_datazoom_show=True,
    )

    grid = Grid(page_title=data['symbol'][0], width=1800, height=900)
    grid.add(kline, grid_bottom='40%')
    grid.add(turnover, grid_top='65%')
    grid.show_config()
    return grid
Exemple #13
0
def brush(data):
    data = hist_sum(data)
    kline = Kline()
    kline.add(
        'Kline',
        data.index,
        data.loc[:, ['open', 'close', 'low', 'high']].values,
        mark_line=['max', 'min'],
        mark_line_valuedim=['highest', 'lowest'],
        is_datazoom_show=True,
        datazoom_xaxis_index=[0, 1],
    )
    brush = Line()
    brush.add(
        'Brush',
        data.index,
        data.endpoint.values,
    )
    overlap = Overlap()
    overlap.add(kline)
    overlap.add(brush)

    macd = Bar()
    macd.add(
        'MACD',
        data.index,
        data.hist_sum.values,
    )
    page = Page()
    page.add(overlap)
    page.add(macd)
    return page
Exemple #14
0
def draw_kline_pic(title: str,
                   labels: list,
                   data_package: list,
                   y_min: int = 0,
                   y_max: int = 100,
                   y_formatter: str = "元人民币",
                   path: str = './charts/k_line.html'):
    """
    K线图
    :param title: 画图标题
    :param labels: 图例
    :param data_package: 数据包
    :param y_min: y轴最小值
    :param y_max: y轴最大值
    :param y_formatter: y轴的格式化
    :param path: 保存的路径
    """
    style = Style(title_top="#fff", title_pos="left", width=1920, height=900)
    kline = Kline(title=title, renderer='svg', **style.init_style)
    kline.add('日K',
              labels,
              data_package,
              yaxis_min=y_min,
              yaxis_max=y_max,
              yaxis_formatter=y_formatter,
              mark_line=["min", "max"],
              mark_point=["min", "max"],
              is_datazoom_show=True,
              datazoom_type="both",
              datazoom_range=[80, 100])
    kline.render(path=path)
Exemple #15
0
def test_kline_datazoom_horizontal():
    kline = Kline("K 线图示例 - dataZoom 水平布局")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              data,
              mark_point=["max"],
              is_datazoom_show=True)
    kline.render()
Exemple #16
0
def echart1(request):
    template = loader.get_template('ewpyecharts.html')

    line = Line("压力分析", width=1200, height=700)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高压力", attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"], mark_line=["average"])
    line.add("最低压力", attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"], legend_top="50%", mark_line=["average"],
             # 设置 dataZoom 控制索引为 0,1 的 x 轴,即第一个和第二个
             is_datazoom_show=True, datazoom_xaxis_index=[0, 1])

    v1 = [[2320.26, 2320.26, 2287.3, 2362.94],
          [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58, 2440.38],
          [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("考核表分析", title_top="50%")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1, is_datazoom_show=True)

    grid = Grid()
    grid.add(line, grid_top="60%")
    grid.add(kline, grid_bottom="60%")
#    grid.render()

    context = dict(
        myechart=grid.render_embed(),
        host=REMOTE_HOST,
        script_list=grid.get_js_dependencies()
    )

    return HttpResponse(template.render(context, request))
Exemple #17
0
def test_kline_user_define_markline_style():
    kline = Kline("K 线图-自定义标记点风格")
    kline.add("日K", DATE, data, mark_point=["min", "max"],
              mark_point_symbolsize=80,
              datazoom_orient='vertical',
              mark_line_valuedim=['lowest', 'highest'])
    kline.show_config()
    kline.render()
Exemple #18
0
def test_not_set():
    from pyecharts import Kline

    kline = Kline("K 线图-默认示例")
    kline.add("日K", [], [])
    kline._option["series"][0]["itemStyle"] = {"normal": {"borderColor": NULL}}
    content = kline._repr_html_()
    assert '"borderColor": null' in content
Exemple #19
0
def kline_chart(code, k_data):
    kline = Kline("{0} K 线图".format(code), width="100%")
    kline.add(("日K"),
              k_data['date'],
              k_data[['open', 'close', 'low', 'high']].values.tolist(),
              mark_point=["average"],
              is_datazoom_show=True,
              datazoom_xaxis_index=[0, 1])
    return kline
 def __init__(self,
              stock_name,
              jsPath='https://cdn.bootcss.com/echarts/4.1.0.rc2'):
     # 使用最新的echarts js文件
     online(jsPath)
     # K线
     self.stock_name = stock_name
     self.kline = Kline(stock_name)
     self.volume_bar = Bar('')
def K_line(date, v1):
    kline = Kline("比特币历史价格")
    kline.add(
        "日K",
        date,
        v1,
        is_datazoom_show=True,
    )
    return kline
Exemple #22
0
def test_kline_default(patched):
    fixture = "kline_options.json"
    patched.return_value = "1"
    kline = Kline("K 线图-默认示例")
    kline.add("日K", DATE, data)
    actual_options = dumps_actual_options(kline.options)
    expected = get_fixture_content(fixture)
    for a, b in zip(actual_options.split("\n"), expected.split("\n")):
        eq_(a.strip(), b.strip())
def K_line(date, v1, name):
    kline = Kline(name)
    kline.add(
        "日K",
        date,
        v1,
        is_datazoom_show=True,
    )
    return kline
Exemple #24
0
def test_kline_user_define_markline_style():
    kline = Kline("K 线图示例 - 自定义标记线风格")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              data,
              mark_line=["max"],
              mark_line_symbolsize=0,
              datazoom_orient='vertical',
              mark_line_valuedim='close')
    kline.render()
Exemple #25
0
def test_grid_6():

    line = Line("折线图示例", width=1200, height=700)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             legend_top="50%",
             mark_line=["average"],
             is_datazoom_show=True,
             datazoom_xaxis_index=[0, 1])

    v1 = [[2320.26, 2320.26, 2287.3,
           2362.94], [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58,
           2440.38], [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例", title_top="50%")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1,
              is_datazoom_show=True)

    grid = Grid()
    grid.add(line, grid_top="60%")
    grid.add(kline, grid_bottom="60%")
    grid.render()
Exemple #26
0
def kline_chart_sh(sh_index_data):
    kline = Kline("上证 K 线图", width="100%", title_top="50%")
    kline.add(("日K"),
              sh_index_data['date'],
              sh_index_data[['open', 'close', 'low', 'high']].values.tolist(),
              mark_point=["average"],
              is_datazoom_show=True,
              datazoom_xaxis_index=[0, 1],
              legend_top="50%")
    return kline
Exemple #27
0
def kplot(kdata,
          new=True,
          axes=None,
          colorup='r',
          colordown='g',
          width=0.6,
          alpha=1.0):
    """绘制K线图
    
    :param KData kdata: K线数据
    :param bool new:    是否在新窗口中显示,只在没有指定axes时生效
    :param axes:        指定的坐标轴
    :param colorup:     the color of the rectangle where close >= open
    :param colordown:   the color of the rectangle where close < open
    :param width:       fraction of a day for the rectangle width
    :param alpha:       the rectangle alpha level, 透明度(0.0~1.0) 1.0为不透明
    """
    if not kdata:
        print("kdata is None")
        return

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

    title = get_draw_title(kdata)
    last_record = kdata[-1]
    text = u'%s 开:%.2f 高:%.2f 低:%.2f 收:%.2f 涨幅:%.2f%%' % (
        last_record.datetime.date(), last_record.openPrice,
        last_record.highPrice, last_record.lowPrice, last_record.closePrice,
        100 *
        (last_record.closePrice - kdata[-2].closePrice) / kdata[-2].closePrice)

    date_list = kdata.getDatetimeList()
    if kdata.getQuery().kType == KQuery.DAY:
        x_list = [d.date() for d in date_list]
    else:
        x_list = [d.datetime() for d in date_list]

    y_list = [[k.openPrice, k.closePrice, k.lowPrice, k.highPrice]
              for k in kdata]

    style = gcf().get_style(axes)
    kline = Kline(title, text, title_pos='center', subtitle_color='#FF0000')
    kline.add(None,
              x_axis=x_list,
              y_axis=y_list,
              mark_line=["max"],
              mark_line_symbolsize=0,
              mark_line_valuedim='highest',
              **style)
    axes.add(kline)

    gcf().set_xaxis(x_list)
    gcf().add_axis(axes)
    return gcf()
Exemple #28
0
def test_kline_datazoom_vertical():
    kline = Kline("K 线图-dataZoom 垂直布局")
    kline.add(
        "日K",
        DATE,
        data,
        mark_line=["max"],
        is_datazoom_show=True,
        datazoom_orient='vertical',
    )
    kline.render()
Exemple #29
0
def test_kline_default(patched):
    patched.return_value = "1"
    kline = Kline("K 线图-默认示例")
    kline.add("日K", DATE, data)
    actual_options = json.dumps(kline.options,
                                sort_keys=True,
                                indent=4,
                                cls=DefaultJsonEncoder)
    expected = get_fixture_content("kline_options.json")
    for a, b in zip(actual_options.split("\n"), expected.split("\n")):
        eq_(a.strip(), b.strip())
Exemple #30
0
def test_kline_datazoom_vertical():
    kline = Kline("K 线图示例 - dataZoom 垂直布局")
    kline.add(
        "日K",
        ["2017/7/{}".format(i + 1) for i in range(31)],
        data,
        mark_line=["max"],
        is_datazoom_show=True,
        datazoom_orient='vertical',
    )
    kline.render()