draw.py 19.3 KB
Newer Older
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
1 2 3 4 5 6 7 8
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : draw.py
# @Time       : 2020/11/19 上午10:51
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
9
import base64
pengxiong's avatar
pengxiong committed
10
import uuid
11 12 13
from urllib import parse

from io import BytesIO
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
14 15

import numpy as np
pengxiong's avatar
pengxiong committed
16
import matplotlib
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
17
import matplotlib.pyplot as plt
18
from matplotlib import ticker
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
19 20 21
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties

pengxiong's avatar
pengxiong committed
22
from app.api.engine import template_folder, work_dir, temp_img_save_folder
pengxiong's avatar
pengxiong committed
23 24

matplotlib.use('Agg')
25
# 中文字体初始化
26
plt.rcParams['font.sans-serif']=['Heiti TC']
27

pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
28 29

def to_percent(temp, position):
30
    return '%.2f' % temp + '%'
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
31

32 33 34

def draw_month_return_chart(xlabels, product_list, cumulative):
    """月度回报表现图"""
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
35

36 37
    # plt.title('Scores by group and gender')
    # plt.ylabel('Scores')
38
    figsize = (24, 12)
39
    # 标签文字大小
40
    fontsize = 15
41
    # 初始化
42
    fig = plt.figure(figsize=figsize)
43
    ax1 = fig.add_subplot(111)
44
    ax2 = ax1.twinx()
45 46
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
47
    width = 0.35  # the width of the bars: can also be len(x) sequence
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
48
    color_list = ['#B0B0B0', '#6C71AA', '#E1BC95', '#F9DBB8']
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
49

50 51 52
    # 坐标轴
    ax1.tick_params(labelsize=fontsize)
    ax2.tick_params(labelsize=fontsize)
53

54
    # 坐标轴颜色
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
55
    ax2.tick_params(axis='y', colors='#D40000')
56 57
    ax1.set_xticks(loc)
    ax1.set_xticklabels(xlabels)
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
58
    # ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
59
    ax2.yaxis.set_major_formatter(FuncFormatter(to_percent))
60 61 62 63
    # temp_rate = np.zeros(max_x_count)
    # for i in range(len(product_list)):
    #     temp_rate += product_list[i]['data']
    # max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
64
    # ax2.set_ylim(0, max_rate + 15)
65 66

    # 柱状图
67 68 69 70 71 72 73 74 75
    prod_legend = []
    for i in range(len(product_list)):
        ax = None
        bottom = np.zeros(max_x_count)
        if i == 0:
            ax = ax1.bar(loc, product_list[i]['data'], width, color=color_list[i], alpha=0.8)
        else:
            for j in range(i):
                bottom = bottom + product_list[j]['data']
76 77 78 79
            if i < len(color_list):
                ax = ax1.bar(loc, product_list[i]['data'], width, bottom=bottom, color=color_list[i], alpha=0.8)
            else:
                ax = ax1.bar(loc, product_list[i]['data'], width, bottom=bottom, alpha=0.8)
80 81
        for a, b in zip(range(len(xlabels)), product_list[0]['data']):
            if b > 0:
82
                ax1.text(a, b*1.08, '%.2f万' % b, ha='center', va='bottom', fontsize=fontsize)
83
            elif b < 0:
84
                ax1.text(a, b*0.92, '%.2f万' % b, ha='center', va='top', fontsize=fontsize)
85
        prod_legend.append(ax[0])
86 87 88
    ax1.legend(prod_legend, [prod['name'] for prod in product_list], loc='upper left', fontsize=fontsize)

    # 画折线图
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
89
    ax2.plot(loc, cumulative['data'], color='#D40000', marker='.', linewidth=3, label=cumulative['name'])
90 91
    # 添加数字标签
    for a, b in zip(range(len(xlabels)), cumulative['data']):
赵杰's avatar
赵杰 committed
92
        ax2.text(a*1.05, b, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize, color='#D40000')
93 94
    ax2.legend(loc='upper center', fontsize=fontsize)

95
    # plt.show()
pengxiong's avatar
pengxiong committed
96 97 98 99 100
    # imgdata = BytesIO()
    # fig.savefig(imgdata, format='png', bbox_inches='tight')
    # imgdata.seek(0)  # rewind the data
    # month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
    filename = str(uuid.uuid4()) + '.png'
pengxiong's avatar
pengxiong committed
101 102 103
    fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
    return_path = template_folder + filename
    return return_path
104 105 106 107 108 109 110


def draw_contribution_chart(xlabels, product_list, cumulative):
    """贡献分解图"""

    # plt.title('Scores by group and gender')
    # plt.ylabel('Scores')
李宗熹's avatar
李宗熹 committed
111
    figsize = (25, 12)
112 113 114 115
    # 标签文字大小
    fontsize = 22
    # 初始化
    fig = plt.figure(figsize=figsize)
赵杰's avatar
赵杰 committed
116
    ax1 = fig.add_subplot(111)
117 118 119 120
    ax2 = ax1.twiny()
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups
    width = 0.35  # the width of the bars: can also be len(x) sequence
121
    color_list = ['#AFAFAF', '#D56666', '#DE7A7A',
赵杰's avatar
赵杰 committed
122 123
                  '#ED9494', '#F4A9A9', '#FFC8C8', '#DEA27A', '#EFAF85',
                  '#FBBF98', '#FFD2B5', '#E1C277', '#EBCD85', '#FEDF96']
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
124

125
    # 坐标轴
126
    ax1.tick_params(labelsize=fontsize)
127
    ax1.set_xticks(loc)
128 129
    ax1.set_xticklabels(xlabels)
    ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
pengxiong's avatar
pengxiong committed
130
    ax1.grid(axis='y')
李宗熹's avatar
李宗熹 committed
131 132 133 134
    # temp_rate = np.zeros(max_x_count)
    # for i in range(len(product_list)):
    #     temp_rate += product_list[i]['data']
    # max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
135
    ax2.set_xticks([])
李宗熹's avatar
李宗熹 committed
136
    # ax2.set_ylim(0, max_rate + 10)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

    # 堆叠柱状图
    prod_legend = []
    for i in range(len(product_list)):
        ax = None
        bottom = np.zeros(max_x_count)
        if i == 0:
            ax = ax1.bar(loc, product_list[i]['data'], width, color=color_list[i], alpha=0.8)
        else:
            for j in range(i):
                bottom = bottom + product_list[j]['data']
            if i < len(color_list):
                ax = ax1.bar(loc, product_list[i]['data'], width, bottom=bottom, color=color_list[i], alpha=0.8)
            else:
                ax = ax1.bar(loc, product_list[i]['data'], width, bottom=bottom, alpha=0.8)
        prod_legend.append(ax[0])
李宗熹's avatar
李宗熹 committed
153
    ax1.legend(prod_legend, [prod['name'] for prod in product_list], bbox_to_anchor=(0.9, -0.1), ncol=4, fontsize=fontsize)
154 155

    # 画折线图
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
156
    ax2.plot(loc, cumulative['data'], color='#B40A15', marker='', linewidth=3, label=cumulative['name'])
pengxiong's avatar
pengxiong committed
157 158
    # 添加数字标签
    for a, b in zip(range(len(xlabels)), cumulative['data']):
159
        ax2.text(a*1.1, b *1.05, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize, color='#B40A15')
160 161
    ax2.legend(loc='upper left', fontsize=fontsize)

pengxiong's avatar
pengxiong committed
162 163 164 165 166 167
    # imgdata = BytesIO()
    # fig.savefig(imgdata, format='png', bbox_inches='tight')
    # imgdata.seek(0)  # rewind the data
    # month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
    # return month_return_img
    filename = str(uuid.uuid4()) + '.png'
pengxiong's avatar
pengxiong committed
168 169 170
    fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
    return_path = template_folder + filename
    return return_path
李宗熹's avatar
李宗熹 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

# def draw_contribution_chart(xlabels, product_list, cumulative):
#     """贡献分解图"""
#
#     # plt.title('Scores by group and gender')
#     # plt.ylabel('Scores')
#     figsize = (25, 12)
#     # 标签文字大小
#     fontsize = 22
#     # 初始化
#     fig = plt.figure(figsize=figsize)
#     ax1 = fig.add_subplot()
#     ax2 = ax1.twiny()
#     max_x_count = max([x['data'].size for x in product_list])
#     loc = np.arange(max_x_count)  # the x locations for the groups
#     width = 0.35  # the width of the bars: can also be len(x) sequence
#     color_list = ['#222A77', '#6C71AA', '#E1BC95', '#F9DBB8']
#
#     # 坐标轴
#     ax1.tick_params(labelsize=fontsize)
#     ax1.set_xticks(loc)
#     ax1.set_xticklabels(xlabels)
#     ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
#     # temp_rate = np.zeros(max_x_count)
#     # for i in range(len(product_list)):
#     #     temp_rate += product_list[i]['data']
#     # max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
#     ax2.set_xticks([])
#     # ax2.set_ylim(0, max_rate + 10)
#
#     # 堆叠柱状图
#     prod_legend = []
#     for i in range(len(product_list)):
#         ax = None
#         for j in range(len(product_list[i]['data'])):
#             product_list[i]['bottom'] = product_list[i].get('bottom', 0)
#             product_list[i]['bottom_neg'] = product_list[i].get('bottom_neg', 0)
#             if j > 0:
#                 product_list[i]['bottom'] += product_list[i].get('bottom', 0)
#                 product_list[i]['bottom_neg'] += product_list[i].get('bottom_neg', 0)
#             if i < len(color_list):
#                 for x in loc:
#                     if product_list[i]['data'][x] >= 0:
#                         ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom'], color=color_list[i], alpha=0.8)
#                     else:
#                         ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom_neg'],
#                                      color=color_list[i], alpha=0.8)
#             else:
#                 for x in loc:
#                     if product_list[i]['data'][x] >= 0:
#                         ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom'], alpha=0.8)
#                     else:
#                         ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom_neg'], alpha=0.8)
#         prod_legend.append(ax[0])
#     # ax1.legend(prod_legend, [prod['name'] for prod in product_list], bbox_to_anchor=(0.9, -0.1), ncol=4, fontsize=fontsize)
#
#     # 画折线图
#     ax2.plot(loc, cumulative['data'], color='#C6A774', marker='', linewidth=3, label=cumulative['name'])
#     ax2.legend(loc='upper left', fontsize=fontsize)
#
#     plt.show()
#     # imgdata = BytesIO()
#     # fig.savefig(imgdata, format='png', bbox_inches='tight')
#     # imgdata.seek(0)  # rewind the data
#     # month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
#     # return month_return_img
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273


def draw_comment_chart(xlabels, source_prod, target_prod):
    """个基点评图"""
    figsize = (20, 12)
    # 标签文字大小
    fontsize = 22
    # 初始化
    fig = plt.figure(figsize=figsize)
    ax1 = fig.add_subplot()
    ax2 = ax1.twiny()
    # ax = plt.gca()  # gca:get current axis得到当前轴
    # ax.spines['bottom'].set_position(('data', 0))  # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
    product_list = [source_prod, target_prod]
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups

    # 坐标轴
    ax1.tick_params(labelsize=fontsize)
    ax2.tick_params(labelsize=fontsize)
    ax1.set_xticks(loc)
    ax1.set_xticklabels(xlabels)
    ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
    max_rate = np.max(np.hstack((source_prod['data'], target_prod['data'])))
    ax2.set_xticks([])

    # 个基折线图
    ax1.plot(loc, source_prod['data'], color='#C6A774', marker='', linewidth=3, label=source_prod['name'])
    ax1.legend(loc='upper left', fontsize=fontsize)

    # 指数折线图
    ax2.plot(loc, target_prod['data'], color='black', marker='', linewidth=3, label=target_prod['name'])
    ax2.legend(loc='upper center', fontsize=fontsize)

    plt.show()


pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
def draw_old_combination_chart(xlabels, origin_combination, index):
    """旧组合对比图"""
    figsize = (20, 12)
    # 标签文字大小
    fontsize = 22
    # 初始化
    fig = plt.figure(figsize=figsize)
    ax1 = fig.add_subplot(111)
    ax3 = ax1.twiny()
    # ax = plt.gca()  # gca:get current axis得到当前轴
    # ax.spines['bottom'].set_position(('data', 0))  # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
    product_list = [origin_combination, index]
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups

    # 坐标轴
    ax1.tick_params(labelsize=fontsize)
    ax3.tick_params(labelsize=fontsize)
    ax1.set_xticks(loc)
    ax1.set_xticklabels(xlabels)
    ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
    ax3.set_xticks([])

    # 新组合折线图
    ax1.plot(loc, origin_combination['data'], color='#C6A774', marker='', linewidth=3, label=origin_combination['name'])
    ax1.legend(loc='upper left', fontsize=fontsize)

    # 指数折线图
    ax3.plot(loc, index['data'], color='black', marker='', linewidth=3, label=index['name'])
    ax3.legend(loc='upper right', fontsize=fontsize)

    # plt.show()
pengxiong's avatar
pengxiong committed
306 307 308 309 310 311
    # imgdata = BytesIO()
    # fig.savefig(imgdata, format='png', bbox_inches='tight')
    # imgdata.seek(0)  # rewind the data
    # return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
    # return return_compare_img
    filename = str(uuid.uuid4()) + '.png'
pengxiong's avatar
pengxiong committed
312 313 314
    fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
    return_path = template_folder + filename
    return return_path
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
315 316


317
def draw_combination_chart(xlabels, new_combination, origin_combination, index):
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
318
    """新组合对比图"""
319 320 321 322 323
    figsize = (20, 12)
    # 标签文字大小
    fontsize = 22
    # 初始化
    fig = plt.figure(figsize=figsize)
324
    ax1 = fig.add_subplot(111)
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    ax2 = ax1.twiny()
    ax3 = ax1.twiny()
    # ax = plt.gca()  # gca:get current axis得到当前轴
    # ax.spines['bottom'].set_position(('data', 0))  # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
    product_list = [origin_combination, new_combination, index]
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups

    # 坐标轴
    ax1.tick_params(labelsize=fontsize)
    ax2.tick_params(labelsize=fontsize)
    ax3.tick_params(labelsize=fontsize)
    ax1.set_xticks(loc)
    ax1.set_xticklabels(xlabels)
    ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
    ax2.set_xticks([])
    ax3.set_xticks([])

    # 新组合折线图
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
344
    ax1.plot(loc, new_combination['data'], color='#C6A774', marker='', linewidth=3, label=new_combination['name'])
345 346 347
    ax1.legend(loc='upper left', fontsize=fontsize)

    # 原组合折线图
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
348
    ax2.plot(loc, origin_combination['data'], color='#222A77', marker='', linewidth=3, label=origin_combination['name'])
349 350 351 352 353
    ax2.legend(loc='upper center', fontsize=fontsize)

    # 指数折线图
    ax3.plot(loc, index['data'], color='black', marker='', linewidth=3, label=index['name'])
    ax3.legend(loc='upper right', fontsize=fontsize)
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
354

355
    # plt.show()
pengxiong's avatar
pengxiong committed
356 357 358 359 360 361
    # imgdata = BytesIO()
    # fig.savefig(imgdata, format='png', bbox_inches='tight')
    # imgdata.seek(0)  # rewind the data
    # return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
    # return return_compare_img
    filename = str(uuid.uuid4()) + '.png'
pengxiong's avatar
pengxiong committed
362 363 364
    fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
    return_path = template_folder + filename
    return return_path
365 366


赵杰's avatar
赵杰 committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
def draw_index_combination_chart(compare_data):
    """基金和指数对比图"""
    xlabels, origin_combination, index = compare_data["xlabels"], compare_data["fund"], compare_data["index"]
    figsize = (20, 12)
    # 标签文字大小
    fontsize = 22
    # 初始化
    fig = plt.figure(figsize=figsize)
    ax1 = fig.add_subplot(111)
    ax3 = ax1.twiny()
    ax1.spines['top'].set_visible(False)
    ax1.spines['right'].set_visible(False)
    ax1.spines['bottom'].set_visible(False)
    ax1.spines['left'].set_visible(False)
    ax3.spines['top'].set_visible(False)
    ax3.spines['right'].set_visible(False)
    ax3.spines['bottom'].set_visible(False)
    ax3.spines['left'].set_visible(False)
    # ax = plt.gca()  # gca:get current axis得到当前轴
    # ax.spines['bottom'].set_position(('data', 0))  # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
    product_list = [origin_combination, index]
    max_x_count = max([x['data'].size for x in product_list])
    loc = np.arange(max_x_count)  # the x locations for the groups

    # 坐标轴
pengxiong's avatar
2  
pengxiong committed
392 393 394 395
    # ax1.tick_params(labelsize=fontsize)
    # ax3.tick_params(labelsize=fontsize)
    # ax1.set_xticks(loc)
    # ax1.set_xticklabels(xlabels)
赵杰's avatar
赵杰 committed
396
    # ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
pengxiong's avatar
2  
pengxiong committed
397 398 399
    # ax1.set_yticks([])
    # ax3.set_yticks([])
    # ax3.set_xticks([])
赵杰's avatar
赵杰 committed
400 401 402 403 404
    ax1.axis('off')
    ax3.axis('off')

    # 基金折线图
    ax1.plot(loc, origin_combination['data'], color='#D40000', marker='', linewidth=3)
pengxiong's avatar
2  
pengxiong committed
405
    # ax1.legend()
赵杰's avatar
赵杰 committed
406 407 408

    # 指数折线图
    ax3.plot(loc, index['data'], color='grey', marker='', linewidth=3)
pengxiong's avatar
2  
pengxiong committed
409
    # ax3.legend()
赵杰's avatar
赵杰 committed
410 411

    # plt.show()
pengxiong's avatar
pengxiong committed
412 413 414 415 416 417
    # imgdata = BytesIO()
    # fig.savefig(imgdata, format='png', bbox_inches='tight')
    # imgdata.seek(0)  # rewind the data
    # return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
    # return return_compare_img
    filename = str(uuid.uuid4()) + '.png'
pengxiong's avatar
pengxiong committed
418
    fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
419
    plt.clf()
pengxiong's avatar
pengxiong committed
420 421
    return_path = template_folder + filename
    return return_path
赵杰's avatar
赵杰 committed
422

pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
423
if __name__ == '__main__':
424 425 426 427 428
    # xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
    # product = {'name': '月度回报率', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    # contrast = {'name': '同比上涨', 'data': np.array([10, 50, 120, 100, 36, 0, 50, 120, 100, 36, 23, 98])}
    # draw_month_return_chart(xlabels, [product], contrast)

李宗熹's avatar
李宗熹 committed
429 430 431 432 433 434 435 436 437 438 439 440
    xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
    product1 = {'name': '塞亚成长1号', 'data': np.array([-10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product2 = {'name': '塞亚成长2号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product3 = {'name': '塞亚成长3号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product4 = {'name': '塞亚成长4号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product5 = {'name': '塞亚成长5号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product6 = {'name': '塞亚成长6号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product7 = {'name': '塞亚成长7号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product8 = {'name': '塞亚成长8号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    product_list = [product1, product2, product3, product4, product5, product6, product7, product8]
    cumulative = {'name': '总收益', 'data': np.array([10, 50, 120, 100, 36, 0, 50, 120, 100, 36, 23, 98])}
    draw_contribution_chart(xlabels, product_list, cumulative)
441 442 443 444 445 446

    # xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
    # source_prod = {'name': '远澜银杏1号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    # target_prod = {'name': '上证指数', 'data': np.array([-10, 10, 5, 55, 24, 10, 20, 8, 10, 31, 40, 32])}
    # draw_comment_chart(xlabels, source_prod, target_prod)

李宗熹's avatar
李宗熹 committed
447 448 449 450 451
    # xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
    # new_combination = {'name': '新组合', 'data': np.array([20, 30, 40, 50, 60, 20, 30, 40, 50, 60, 50, 60])}
    # origin_combination = {'name': '原组合', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
    # index = {'name': '上证指数', 'data': np.array([-10, 10, 5, 55, 24, 10, 20, 8, 10, 31, 40, 32])}
    # draw_combination_chart(xlabels, new_combination, origin_combination, index)