Commit c2b34bdf authored by pengxiong's avatar pengxiong

fix10

parent 94dc2f78
......@@ -7,6 +7,7 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
import uuid
from urllib import parse
from io import BytesIO
......@@ -18,6 +19,7 @@ from matplotlib import ticker
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
from app.api.engine import template_folder, work_dir, temp_img_save_folder
matplotlib.use('Agg')
# 中文字体初始化
......@@ -91,11 +93,14 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2.legend(loc='upper center', 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
# 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'
fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
return_path = template_folder + filename
return return_path
def draw_contribution_chart(xlabels, product_list, cumulative):
......@@ -154,11 +159,15 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax2.text(a*1.1, b *1.05, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize, color='#B40A15')
ax2.legend(loc='upper left', fontsize=fontsize)
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
# 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'
fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
return_path = template_folder + filename
return return_path
# def draw_contribution_chart(xlabels, product_list, cumulative):
# """贡献分解图"""
......@@ -294,11 +303,15 @@ def draw_old_combination_chart(xlabels, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
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
# 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'
fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
return_path = template_folder + filename
return return_path
def draw_combination_chart(xlabels, new_combination, origin_combination, index):
......@@ -340,11 +353,15 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
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
# 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'
fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
return_path = template_folder + filename
return return_path
def draw_index_combination_chart(compare_data):
......@@ -392,11 +409,16 @@ def draw_index_combination_chart(compare_data):
# ax3.legend()
# plt.show()
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
# 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'
fig.savefig(temp_img_save_folder + filename, format='png', bbox_inches='tight')
plt.clf()
return_path = template_folder + filename
return return_path
if __name__ == '__main__':
# 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')
......
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