123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import matplotlib.pyplot as plt
- import json
- from matplotlib.animation import FuncAnimation
- import threading
- def read_data():
- try:
- return json.load(open("/tmp/values.pickle", 'r'))
- except:
- return (0.0, {})
- def write_data(values):
- json.dump(values, open("/tmp/values.pickle", 'w'))
- plt.ion()
- plt.figure()
- old_time, d = read_data()
- l = raw_input()
- time, _ = l.split(" ", 1)
- time = float(time)
- if time <= old_time:
- # Overwrites current values, so flush
- d = {}
- first = l
- maps = {}
- while 1:
- if first is not None:
- l = first
- first = None
- else:
- l = raw_input()
- if l == "CLOSE":
- import sys
- sys.exit(0)
- elif l == "ALGEBRAIC_LOOP":
- print("Algebraic loop discovered...")
- continue
- time, key, value = l.split(" ")
- time = float(time)
- value = float(value)
- if key not in d:
- maps[key], = plt.plot([], [])
- maps[key].set_label(key)
- plt.legend()
- d[key] = ([], [])
- d[key][0].append(time)
- d[key][1].append(value)
- maps[key].set_xdata(d[key][0])
- maps[key].set_ydata(d[key][1])
- plt.draw()
- write_data((0.0, d))
|