月度回报更新2

parent 71535598
......@@ -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']=['simsunb.ttf']
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 = (24, 12)
# 标签文字大小
fontsize = 20
fontsize = 15
# 初始化
fig = plt.figure(figsize=figsize)
ax1 = fig.add_subplot(111)
......@@ -41,16 +45,17 @@ 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))
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'])))
# 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)
# 柱状图
......@@ -82,8 +87,12 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2.text(a, b + 0.1, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize)
ax2.legend(loc='upper center', fontsize=fontsize)
plt.show()
plt.savefig("")
# 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):
......
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