-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
60 lines (41 loc) · 1.18 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# import base64
from io import BytesIO
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib as mpl
mpl.use('Agg')
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
order_by_sql = f"order by {x_axis_column_name}" if x_axis_column_dtype == 'date' else ''
sql = f"select {x_axis_column_name},{','.join(y_axis_column_name)} from {table_name} where scrip_code = 532215 {order_by_sql}"
res = plpy.execute(sql)
xaxis = []
if x_axis_column_dtype == 'date':
for row in res:
dstr = row[x_axis_column_name]
ddate = datetime.strptime(dstr, '%Y-%m-%d')
xaxis.append(ddate)
# print(xaxis)
count = 0
for col in y_axis_column_name:
yaxis = []
for row in res:
d = row[col]
yaxis.append(d)
plt.plot(xaxis, yaxis, label=col)
plt.xlabel(x_axis_column_name)
plt.ylabel("Close Params")
plt.title("Simple Plot")
plt.legend()
buffer = BytesIO()
plt.savefig(buffer, format="png")
plt.clf()
plt.close()
buffer.seek(0)
image_png = buffer.getvalue()
buffer.close()
return image_png
# graphic = base64.b64encode(image_png)
# graphic = graphic.decode('utf-8')
# return graphic