12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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:
- print("Wait for input")
- l = raw_input()
- print("Plotting values: " + l)
- 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] = ([], [])
- print("Update")
- d[key][0].append(time)
- d[key][1].append(value)
- maps[key].set_xdata(d[key][0])
- maps[key].set_ydata(d[key][1])
- print("Drawing")
- plt.draw()
- write_data((0.0, d))
|