draw更新

parent 5b54bce1
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,6 +6,10 @@
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
from urllib import parse
from io import BytesIO
import numpy as np
import matplotlib.pyplot as plt
......@@ -14,11 +18,11 @@ from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
# 中文字体初始化
plt.rcParams['font.sans-serif']=['SimSun']
plt.rcParams['font.sans-serif']=['Heiti TC']
def to_percent(temp, position):
return '%1.0f' % temp + '%'
return '%.2f' % temp + '%'
def draw_month_return_chart(xlabels, product_list, cumulative):
......@@ -28,7 +32,7 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
# plt.ylabel('Scores')
figsize = (20, 12)
# 标签文字大小
fontsize = 20
fontsize = 15
# 初始化
fig = plt.figure(figsize=figsize)
ax1 = fig.add_subplot(111)
......@@ -41,17 +45,18 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
# 坐标轴
ax1.tick_params(labelsize=fontsize)
ax2.tick_params(labelsize=fontsize)
# 坐标轴颜色
ax2.tick_params(axis='y', colors='#C6A774')
ax1.set_xticks(loc)
ax1.set_xticklabels(xlabels)
ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
# ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
ax2.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_ylim(0, max_rate + 15)
# 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_ylim(0, max_rate + 15)
# 柱状图
prod_legend = []
......@@ -74,7 +79,12 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2.plot(loc, cumulative['data'], color='#C6A774', marker='', linewidth=3, label=cumulative['name'])
ax2.legend(loc='upper center', fontsize=fontsize)
plt.show()
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
def draw_contribution_chart(xlabels, product_list, cumulative):
......
......@@ -3,6 +3,8 @@ from app.service.result_service import UserCustomerResultAdaptor
# 准备数据
from app.utils.draw import draw_month_return_chart
ifa_id = 'USER_INFO15914346866762'
customer_id = '202009281545001'
......@@ -20,9 +22,11 @@ now_yield = round((df['contribution_decomposition']-1)*100,2)
index_yield = round((df["index_result"]["return_ratio"]-1)*100, 2)
now_withdrawal = round(df["max_drawdown"][0]*100,2)
index_withdrawal = round(df["index_result"]["max_drawdown"][0]*100, 2)
monthly_return_performance_pic = '_'.join((ifa_id, customer_id, '20201109', 'monthly_return_performance.png'))
image_dir = './img/'
monthly_return_performance_pic = image_dir + monthly_return_performance_pic
# monthly_return_performance_pic = '_'.join((ifa_id, customer_id, '20201109', 'monthly_return_performance.png'))
# image_dir = './img/'
# monthly_return_performance_pic = image_dir + monthly_return_performance_pic
xlabels, product_list, cumulative = user_customer.get_month_return_chart()
monthly_return_performance_pic = draw_month_return_chart(xlabels, product_list, cumulative)
# 组合数据
group_result = d["default"]
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment