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
27d4cde4
Commit
27d4cde4
authored
Dec 01, 2020
by
pengxiong@wealthgrow.cn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
月度回报更新2
parent
71535598
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
draw.py
app/utils/draw.py
+18
-9
No files found.
app/utils/draw.py
View file @
27d4cde4
...
...
@@ -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.0
f'
%
temp
+
'
%
'
return
'
%
.2
f'
%
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
,
'
%.2
f'
%
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
):
...
...
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