1 | import socket
|
2 | import matplotlib.animation as animation
|
3 | from matplotlib.widgets import Button,MultiCursor
|
4 | import pylab as py
|
5 |
|
6 |
|
7 | fig = py.figure(1)
|
8 |
|
9 | ###################################
|
10 | #Adds the first axis with settings#
|
11 | ###################################
|
12 | ax1 = fig.add_subplot(211,xlim=(-10, 50), ylim=(20, 120))
|
13 | dPredLine, = ax1.plot([],[])
|
14 | py.title('Prediction EcoRoll')
|
15 | py.ylabel('d in [m]')
|
16 | py.grid(True)
|
17 | py.axvline(x=ERminTime, color='k', alpha=0.3)
|
18 | py.axvline(x=0, color='k')
|
19 |
|
20 | ####################################
|
21 | #Adds the second axis with settings#
|
22 | ####################################
|
23 | ax2 = py.subplot(212, xlim=(-10, 50), ylim=(-3, 3))
|
24 | vPredLine, = ax2.plot([],[])
|
25 | py.ylabel('v in [m/s]')
|
26 | py.xlabel('time in [s]')
|
27 | py.grid(True)
|
28 | py.axvline(x=ERminTime, color='k', alpha=0.3)
|
29 | py.axvline(x=0, color='k')
|
30 |
|
31 |
|
32 | def init():
|
33 | ax2.yaxis.label.set_color('k')
|
34 | ax2.spines['bottom'].set_color('k')
|
35 | ax2.spines['top'].set_color('k')
|
36 | ax2.spines['right'].set_color('k')
|
37 | ax2.spines['left'].set_color('k')
|
38 | ax1.yaxis.label.set_color('k')
|
39 | ax1.spines['bottom'].set_color('k')
|
40 | ax1.spines['top'].set_color('k')
|
41 | ax1.spines['right'].set_color('k')
|
42 | ax1.spines['left'].set_color('k')
|
43 | return ax1, ax2
|
44 |
|
45 | def animate_Pred(i):
|
46 | if (ax1.yaxis.label.get_color() == 'g') and (ax2.yaxis.label.get_color() == 'g'): # if ER is active
|
47 | print("ER active")
|
48 | if (ndataList[5]<0):
|
49 | set_ax1Color('r')
|
50 | if (ndataList[7]<0):
|
51 | set_ax2Color('r')
|
52 | else: #ER is not active
|
53 | if (ndataList[4]<6) or (ndataList[5]<6): #ER is not active because of d prediction
|
54 | set_ax1Color('r')
|
55 | print("dpred supress ER")
|
56 | else:
|
57 | set_ax1Color('g')
|
58 | if (ndataList[6]<6) or (ndataList[7]<6): #ER is not active because of v rel prediction
|
59 | set_ax2Color('r')
|
60 | print("vrelPred supress ER")
|
61 | else:
|
62 | set_ax2Color('g')
|
63 | return ax1, ax2
|
64 |
|
65 | def set_ax1Color(c):
|
66 | ax1.yaxis.label.set_color(c)
|
67 | ax1.tick_params(axis='y', colors=c)
|
68 | ax1.spines['bottom'].set_color(c)
|
69 | ax1.spines['top'].set_color(c)
|
70 | ax1.spines['right'].set_color(c)
|
71 | ax1.spines['left'].set_color(c)
|
72 |
|
73 | def set_ax2Color(c):
|
74 | ax2.yaxis.label.set_color(c)
|
75 | ax2.tick_params(axis='y', colors=c)
|
76 | ax2.spines['bottom'].set_color(c)
|
77 | ax2.spines['top'].set_color(c)
|
78 | ax2.spines['right'].set_color(c)
|
79 | ax2.spines['left'].set_color(c)
|
80 |
|
81 | ani = animation.FuncAnimation(fig, animate_Pred, py.arange(1, 200), init_func=init, interval=40, blit=True)
|
82 |
|
83 | py.show()
|