-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
110 lines (89 loc) · 4.21 KB
/
plot.py
File metadata and controls
110 lines (89 loc) · 4.21 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as date
from matplotlib.lines import Line2D
import os, datetime
from numpy_process import *
def create_fig(dimension_x, dimension_y):
if (dimension_x == None or dimension_y == None):
flg, plot = plt.subplots()
else:
flg, plot = plt.subplots(dimension_x, dimension_y)
return flg, plot
def setting_fig(fig, title):
fig.canvas.set_window_title(title)
def legend_label(color, label_name):
label = Line2D([0], [0], color = color, lw = 4, label = label_name)
return label
def plot_legend(plot, handle):
plot.legend(handles = handle)
def addPlot_under(fig, location):
addPlot = fig.add_subplot(location,1,location)
return addPlot
def scatter(plot, x_data, y_data, name, plot_name, setColor, scale, option = "add"):
if (option == "basic"):
plt.scatter(x_data, y_data, color = setColor, s = scale, label = name)
plt.title(plot_name)
else:
plot.scatter(x_data, y_data, color = setColor, s= scale, label = name)
plot.set_title(plot_name)
plot.grid(alpha = 0.3)
def line(plot, x_data, y_data, name, plot_name, setColor, thickness, option = "add"):
if (option == "basic"):
plt.plot(x_data, y_data, color = setColor, linewidth = thickness, label = name)
plt.title(plot_name)
elif(option == "singleArr"):
plot.plot(x_data, color = setColor, linewidth = thickness, label = name)
plot.set_title(plot_name)
else:
plot.plot(x_data, y_data, color = setColor, linewidth = thickness, label = name)
plot.set_title(plot_name)
plot.grid(alpha = 0.3)
def basic4info_fig(x_arr, y_arr, itemId, fig_name, thickness, save = True, damageList = []):
print(" ========================== ")
print(" basic original plot ")
print(" original / mean / var / std ")
print(" damaged item id : " + str(damageList))
print(" ========================== ")
data_row = y_arr.shape[0]
basic4 = ["original", "mean", "var", "std"]
fig, plot = create_fig(2, 2)
line(plot[0,1], arrArange(data_row), array_cal_each_id(y_arr, cal = "mean"), "mean", basic4[1], "blue", thickness)
line(plot[1,0], arrArange(data_row), array_cal_each_id(y_arr, cal = "var"), "var", basic4[2], "blue", thickness)
line(plot[1,1], arrArange(data_row), array_cal_each_id(y_arr, cal = "std"), "std", basic4[3], "blue", thickness)
for i in range(data_row):
if( str(itemId[i]) in damageList):
line(plot[0,0], x_arr, y_arr[i], itemId[i], basic4[0], "red", 2)
scatter(plot[0,1], i, array_cal_each_id(y_arr, cal = "mean")[i], "mean", basic4[1], "red", 5)
scatter(plot[1,0], i, array_cal_each_id(y_arr, cal = "var")[i], "var", basic4[2], "red", 5)
scatter(plot[1,1], i, array_cal_each_id(y_arr, cal = "std")[i], "std", basic4[3], "red", 5)
else:
line(plot[0,0], x_arr, y_arr[i], "original", basic4[0], "blue", 0.1)
print(" - drawing plot ... {}".format(i+1) + " / " + "{}".format(data_row) , end = "\r")
print("\n")
fig_name += "_basic4info"
setting_fig(fig, fig_name)
plot_show(fig, fig_name, save)
def plot_show(fig, name, save = True):
manager = plt.get_current_fig_manager()
#print("backend : " + str(matplotlib.get_backend()))
if (matplotlib.get_backend() == 'TkAgg'):
manager.window.state('zoomed')
elif(matplotlib.get_backend() == 'wxAgg'):
manager.frame.Maximize(True)
elif(matplotlib.get_backend() == 'QT4Agg'):
manager.window.showMaximized()
if(save == True):
plot_save(fig, name)
plt.show()
def plot_save(fig, logName):
fig.set_size_inches(19.2,10.8)
project_root = os.path.abspath(os.path.dirname(__file__))
dir_name = "plot_log"
save_root = os.path.join(project_root, dir_name)
if not os.path.exists(save_root):
os.mkdir(save_root)
nowDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S").replace(":","_")
saveName = logName + nowDate
save_full_root = os.path.join(save_root, saveName)
fig.savefig(save_full_root, dpi=100, bbox_inches='tight')