1
0

add dynamic display

This commit is contained in:
Thibault Barnouin
2021-10-16 03:32:22 +02:00
parent 0a70bb36de
commit b452bee164
2 changed files with 50 additions and 2 deletions

48
lib/plots.py Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
Implementation of the plotting and visualization functions.
"""
import numpy as np
import matplotlib.pyplot as plt
class DynamicUpdate():
#Suppose we know the x range
min_x = -10
max_x = 10
def on_launch(self):
#Set up plot
self.figure, self.ax = plt.subplots()
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)
#Other stuff
self.ax.grid()
def on_running(self, xdata, ydata):
#Update data (with the new _and_ the old points)
self.lines.set_xdata(xdata)
self.lines.set_ydata(ydata)
#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()
#Example
def __call__(self):
import numpy as np
import time
self.on_launch()
xdata = []
ydata = []
for x in np.arange(0,10,0.5):
xdata.append(x)
ydata.append(np.exp(-x**2)+10*np.exp(-(x-7)**2))
self.on_running(xdata, ydata)
time.sleep(1)
return xdata, ydata

View File

@@ -6,7 +6,7 @@ from lib.integrator import frogleap
def main():
#initialisation
m = np.array([10, 2, 2])
m = np.array([100, 2, 2])
x1 = np.array([0, 0, 0])
x2 = np.array([1, 0, 0])
@@ -18,7 +18,7 @@ def main():
v3 = np.array([1, 0, 0])
p = m*np.array([v1, v2, v3])
q, p = frogleap(10, 1, m, q, p)
q, p = frogleap(10, 1, m, q, p, display=True)
return 0
if __name__ == '__main__':