modify initialisation parameters and add gif animation saving
This commit is contained in:
14
lib/plots.py
14
lib/plots.py
@@ -4,6 +4,7 @@
|
||||
Implementation of the plotting and visualization functions.
|
||||
"""
|
||||
import numpy as np
|
||||
import time
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
class DynamicUpdate():
|
||||
@@ -16,24 +17,29 @@ class DynamicUpdate():
|
||||
def on_launch(self):
|
||||
#Set up plot
|
||||
self.figure, self.ax = plt.subplots()
|
||||
self.lines, = self.ax.plot([],[], 'o')
|
||||
self.lines, = self.ax.plot([],[],'o')
|
||||
#Autoscale on unknown axis and known lims on the other
|
||||
self.ax.set_autoscaley_on(True)
|
||||
#self.ax.set_xlim(self.min_x, self.max_x)
|
||||
#self.ax.set_ylim(self.min_x, self.max_x)
|
||||
self.ax.set_xlim(self.min_x, self.max_x)
|
||||
self.ax.set_ylim(self.min_x, self.max_x)
|
||||
#Other stuff
|
||||
self.ax.grid()
|
||||
self.ax.set_aspect('equal')
|
||||
|
||||
def on_running(self, xdata, ydata):
|
||||
def on_running(self, xdata, ydata, step=None, label=None):
|
||||
#Update data (with the new _and_ the old points)
|
||||
self.lines.set_xdata(xdata)
|
||||
self.lines.set_ydata(ydata)
|
||||
if not label is None:
|
||||
self.ax.set_title(label)
|
||||
#Need both of these in order to rescale
|
||||
self.ax.relim()
|
||||
self.ax.autoscale_view()
|
||||
#We need to draw *and* flush
|
||||
self.figure.canvas.draw()
|
||||
self.figure.canvas.flush_events()
|
||||
if not step is None and step%10==0:
|
||||
self.figure.savefig("tmp/{0:05d}.png".format(step),bbox_inches="tight")
|
||||
|
||||
#Example
|
||||
def __call__(self):
|
||||
|
||||
Reference in New Issue
Block a user