-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisualizer.py
187 lines (130 loc) · 5.56 KB
/
visualizer.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import subprocess
import sys
import copy
from scipy import interpolate
from backend import *
backend = Backend(*sys.argv[1:])
def tryParse(s):
try:
return int(s)
except:
return 1
i=0
factor=1
mv = 10
#matplotlib.rcParams['patch.edgecolor'] = 'FFFFFF'
matplotlib.rcParams['axes.facecolor'] = '000000'
matplotlib.rcParams['axes.edgecolor'] = 'AAAAAA'
#matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']
matplotlib.rcParams['text.color'] = 'AAAAAA'
#matplotlib.rcParams['xtick.alignment'] = 'top'
#matplotlib.rcParams['ytick.alignment'] = 'center_baseline'
#matplotlib.rcParams['xtick.direction'] = 'in'
#matplotlib.rcParams['ytick.direction'] = 'in'
matplotlib.rcParams['ytick.color'] = 'AAAAAA'
matplotlib.rcParams['xtick.color'] = 'AAAAAA'
#matplotlib.rcParams['xtick.color'] = 'FFFFFF'
#matplotlib.rcParams['ytick.labelright'] = True
matplotlib.rcParams['xtick.labelbottom'] = True
#matplotlib.rcParams['xtick.labeltop'] = True
matplotlib.rcParams['text.latex.preview'] = True
#matplotlib.rcParams['toolbar'] = 'None'
plt.rcParams.update({'font.size': 6})
szpp = 2 #3
fig = plt.figure(figsize=(szpp, szpp), facecolor=[0,0,0,1])
#print(matplotlib.rcParams.keys())
subplots = []
#XXX block vis thread when receiving incoming message.
def visualize(plotsInCol=3):
global subplots
global fig
bk = backend.Z
amountPlots = len(bk)
if amountPlots == 0: return
rows = int(np.ceil(amountPlots / plotsInCol))
cols = int(min(amountPlots, plotsInCol))
if rows != len(subplots) or len(subplots) == 0 or cols != len(subplots[0]):
plt.close("all")
fig = plt.figure(figsize=(szpp*cols,szpp*rows), facecolor=[0,0,0,1])
plt.subplots_adjust(0.14 / cols, 0.10 / rows, 1 - .02 / cols, 1-.10 / rows)
#plt.subplots_adjust(0.04, 0.06, 0.97, 0.94)
subplots = [[plt.subplot(rows, cols, r*cols + c+1) for c in range(cols)] for r in range(rows)]
ke = copy.deepcopy(list(bk.keys())) #< everything that used to be there will be there.
for plti, i in enumerate(ke[:amountPlots]):
assert(type(bk) is dict)
#sp = plt.subplot(rows, cols, plti+1)
sp = subplots[int(np.floor(plti / cols))][plti % cols]
sp.clear()
for j in bk[i]:
lkz = bk[i][j][1]
tkz = bk[i][j][0]
name = j if j else i
if lkz.shape[0]:
#
# Should work with arbritrary awmount of parameters
if tkz == "scatter" or tkz == "points" or tkz == "histogram":
x = lkz[:,0] if lkz.shape[1] > 1 else np.arange(lkz.shape[0])
yy = lkz[:,1:] if lkz.shape[1] > 1 else lkz[:,0:1]
yy = yy.T
sheep = yy.shape[0]#< everything that used to be there will be there.
titles=[]
if tkz == "histogram":
for en in range(lkz.T.shape[0]):
titles += [ "[" + str(en) + "]"]
sp.hist(lkz, label=titles)
else:
for en in range(sheep):
y = yy[en]
if tkz == "points":
sp.plot(x, y,
label= name + ("[" + str(en) + "]" if yy.shape[0] > 1 else ""))
else:
sp.plot(x, y,
label= name + ("[" + str(en) + "]" if yy.shape[0] > 1 else ""))
elif tkz == "interval" :
if (lkz.shape[1] == 2 or lkz.shape[1] == 3):
assert(lkz.shape[1] == 2 or lkz.shape[1] == 3)
x = np.hstack((lkz[:,0:2], np.ones(lkz.shape[0])[:,np.newaxis] * np.nan)).flatten()
y = np.ones(x.shape[0]) * (lkz[0,2] if lkz.shape[1] == 3 else tryParse(j))
sp.plot(x, y, label= name)
sp.legend()
sp.set_title(name)
def walk(multithreaded=True):
if multithreaded: backend.start()
while True:
if not multithreaded: backend.receiveVal()
visualize()
plt.pause(1)
walk()
while False:
# read core temperature
#process = subprocess.Popen(['less /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp?_input | xargs'], stdout=subprocess.PIPE, shell=True, stderr=subprocess.PIPE)
#output, error = process.communicate()
#ii=i*factor
#v[ii] = np.fromstring(output, dtype=int, sep=" ") / 1000
#mv = max(np.max(v[ii]) + 5, mv)
#if i > 2 and factor > 1:
# tck = [interpolate.splrep(ara[:ii:factor], v[:ii:factor,j],k=2) for j in range(3)]
# v[:ii] = np.array([interpolate.splev(ara[:ii], tck[j]) for j in range(3)]).T
#ax2.clear()
colors = [(.6, .5, .5), (.5, .6, .5), (.5, .5, .6)]
steigung = not True
abrt = ii if steigung else ii-3
if abrt > 0:
for k in range(3):
ax.plot(ara[:abrt], v[:abrt, k], color=colors[k], label=str(k))
ax2.hist(v[:abrt:factor], color=colors, label=["1", "2", "3"])
ax.grid(color=(.08, .11, .11), linestyle=':', linewidth=1)
ax2.grid(color=(.08, .11, .11), linestyle=':', linewidth=1)
ax.set_ylim([20, mv])
plt.pause(1)
i+=1
if abrt == 1:
ax.legend()
ax2.legend()
ax2.set_title("ax2")
ax.set_title("ax1")
#plt.suptitle("supertitle")