-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample_matplotlib_with_datetime.py
More file actions
38 lines (30 loc) · 1 KB
/
sample_matplotlib_with_datetime.py
File metadata and controls
38 lines (30 loc) · 1 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
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import datetime
from numpy_buffer import RingBuffer
def main():
maxlen = 500
data_x = RingBuffer(maxlen, datetime.datetime.utcnow(), dtype=datetime.datetime)
data_y = RingBuffer(maxlen)
y = 100 # initial value
fig, ax = plt.subplots()
line, = ax.plot(data_x.all[::-1], data_y.all[::-1], linestyle='-', marker='+', color='r', markeredgecolor='b')
delta_y = 20
ax.set_ylim([y - delta_y, y + delta_y])
while True:
x = datetime.datetime.utcnow()
y = y + np.random.uniform(-1, 1)
data_x.append(x)
data_y.append(y)
line.set_xdata(data_x.all[::-1])
xmin, xmax = data_x.min(), data_x.max()
if xmax > xmin:
ax.set_xlim([xmin, xmax])
line.set_ydata(data_y.all[::-1])
ymin, ymax = data_y.min(), data_y.max()
if ymax > ymin:
ax.set_ylim([ymin, ymax])
plt.pause(0.001)
if __name__ == '__main__':
main()