1
0

modify display to 3d output

This commit is contained in:
Thibault Barnouin
2021-10-30 18:44:31 +02:00
parent 4c2ea51c28
commit b8b367b75b

View File

@@ -16,30 +16,31 @@ class DynamicUpdate():
def on_launch(self): def on_launch(self):
#Set up plot #Set up plot
self.figure, self.ax = plt.subplots() self.fig = plt.figure()
self.lines, = self.ax.plot([],[],'o') self.ax = self.fig.add_subplot(projection='3d')
self.lines, = self.ax.plot([],[],[],'o')
#Autoscale on unknown axis and known lims on the other #Autoscale on unknown axis and known lims on the other
self.ax.set_autoscaley_on(True) self.ax.set_autoscaley_on(True)
self.ax.set_xlim(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) self.ax.set_ylim(self.min_x, self.max_x)
self.ax.set_zlim(self.min_x, self.max_x)
#Other stuff #Other stuff
self.ax.grid() self.ax.grid()
self.ax.set_aspect('equal') #self.ax.set_aspect('equal')
def on_running(self, xdata, ydata, step=None, label=None): def on_running(self, xdata, ydata, zdata, step=None, label=None):
#Update data (with the new _and_ the old points) #Update data (with the new _and_ the old points)
self.lines.set_xdata(xdata) self.lines.set_data_3d(xdata, ydata, zdata)
self.lines.set_ydata(ydata)
if not label is None: if not label is None:
self.ax.set_title(label) self.ax.set_title(label)
#Need both of these in order to rescale #Need both of these in order to rescale
self.ax.relim() self.ax.relim()
self.ax.autoscale_view() self.ax.autoscale_view()
#We need to draw *and* flush #We need to draw *and* flush
self.figure.canvas.draw() self.fig.canvas.draw()
self.figure.canvas.flush_events() self.fig.canvas.flush_events()
if not step is None and step%10==0: if not step is None and step%50==0:
self.figure.savefig("tmp/{0:05d}.png".format(step),bbox_inches="tight") self.fig.savefig("tmp/{0:05d}.png".format(step),bbox_inches="tight")
#Example #Example
def __call__(self): def __call__(self):