-
Notifications
You must be signed in to change notification settings - Fork 2
/
draw_chart.py
59 lines (48 loc) · 1.47 KB
/
draw_chart.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/13 11:22
# @Author : wendy
# @Usage : Use prediction final result to drawchart
# @File : draw_chart.py
# @Software: PyCharm
import plotly.graph_objs as go
import plotly.offline as off
from model.Config import Config as C
from utils import helper as hp
C = C()
def draw(result_set,zebra):
print('Ploting the image now...')
plot_dir = C.PREDICT_RESULT_IMAGE
hp.mkdir(plot_dir)
save_name = zebra.get_name()
max_density = zebra.get_max_type()
x_list = []
y_list = []
max_list = []
for name,result in result_set.items():
x_list.append(name)
y_list.append(result)
max_list.append(round(zebra.get_current_max_density(max_density),2))
print('Saving html image under ',plot_dir)
draw_line_plot(x_list,y_list,max_list,save_name,plot_dir)
def draw_line(list_x,list_y,name):
trace= go.Scatter(
x=list_x,
y=list_y,
mode='lines',
name= name
)
return trace
def draw_line_with_markers(list_x,list_y,name):
trace = go.Scatter(
x=list_x,
y=list_y,
mode='lines+markers',
name= name
)
return trace
def draw_line_plot(list_x,list_y,max_list,title,save_dir):
trace1 = draw_line_with_markers(list_x,list_y,'result_density')
trace2 = draw_line_with_markers(list_x,max_list,'max_density')
data = [trace1,trace2]
off.plot(data,filename=save_dir+title+'.html',auto_open=False)