Browse Source

Automatically update x-limit

Yentl Van Tendeloo 7 years ago
parent
commit
b96a2b8275
1 changed files with 11 additions and 3 deletions
  1. 11 3
      interface/simple_plot/main.py

+ 11 - 3
interface/simple_plot/main.py

@@ -20,14 +20,19 @@ l = raw_input()
 time, _ = l.split(" ", 1)
 time = float(time)
 
+maps = {}
+
 if time <= old_time:
     # Overwrites current values, so flush
     d = {}
+else:
+    for key in d:
+        maps[key], = plt.plot(d[key][0], d[key][1])
+        maps[key].set_label(key)
+    plt.legend()
 
 first = l
 
-maps = {}
-
 while 1:
     if first is not None:
         l = first
@@ -45,15 +50,18 @@ while 1:
     time = float(time)
     value = float(value)
 
-    if key not in d:
+    if key not in maps:
         maps[key], = plt.plot([], [])
         maps[key].set_label(key)
         plt.legend()
+
+    if key not in d:
         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.gca().set_xlim([min(d[key][0]), max(d[key][0])])
     plt.draw()
     write_data((0.0, d))