Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
fund_report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
fund_report
Commits
c2b34bdf
Commit
c2b34bdf
authored
Jan 22, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix10
parent
94dc2f78
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
25 deletions
+47
-25
draw.py
app/utils/draw.py
+47
-25
No files found.
app/utils/draw.py
View file @
c2b34bdf
...
...
@@ -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
,
'
%.2
f'
%
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')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment