File tree 1 file changed +23
-1
lines changed
Python/Matplotlib/09-LiveData
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Another way to do it without clearing the Axis
2
+ from itertools import count
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ from matplotlib.animation import FuncAnimation
6
+
7
+ plt.style.use('fivethirtyeight')
8
+
9
+ x_vals = []
10
+ y_vals = []
11
+
12
+ plt.plot([], [], label='Channel 1')
13
+ plt.plot([], [], label='Channel 2')
14
+
2
15
3
16
def animate(i):
4
17
data = pd.read_csv('data.csv')
5
18
x = data['x_value']
6
19
y1 = data['total_1']
7
20
y2 = data['total_2']
8
21
22
+ ax = plt.gca()
23
+ line1, line2 = ax.lines
24
+
9
25
line1.set_data(x, y1)
10
26
line2.set_data(x, y2)
11
27
12
- ax = plt.gca()
13
28
xlim_low, xlim_high = ax.get_xlim()
14
29
ylim_low, ylim_high = ax.get_ylim()
15
30
@@ -24,3 +39,10 @@ def animate(i):
24
39
current_ymin = y1min if (y1min < y2min) else y2min
25
40
26
41
ax.set_ylim((current_ymin - 5), (current_ymax + 5))
42
+
43
+
44
+ ani = FuncAnimation(plt.gcf(), animate, interval=1000)
45
+
46
+ plt.legend()
47
+ plt.tight_layout()
48
+ plt.show()
You can’t perform that action at this time.
0 commit comments