From 5a31a8edcc9e98d656e496af7dcfbda5711b22d4 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 17 Nov 2022 09:48:29 -0500 Subject: [PATCH] Backport PR #24481: Fix floating-point drift in oscilloscope example --- examples/animation/strip_chart.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/animation/strip_chart.py b/examples/animation/strip_chart.py index 5e3b8fea0d04..f06413c28661 100644 --- a/examples/animation/strip_chart.py +++ b/examples/animation/strip_chart.py @@ -26,13 +26,16 @@ def __init__(self, ax, maxt=2, dt=0.02): def update(self, y): lastt = self.tdata[-1] - if lastt > self.tdata[0] + self.maxt: # reset the arrays + if lastt >= self.tdata[0] + self.maxt: # reset the arrays self.tdata = [self.tdata[-1]] self.ydata = [self.ydata[-1]] self.ax.set_xlim(self.tdata[0], self.tdata[0] + self.maxt) self.ax.figure.canvas.draw() - t = self.tdata[-1] + self.dt + # This slightly more complex calculation avoids floating-point issues + # from just repeatedly adding `self.dt` to the previous value. + t = self.tdata[0] + len(self.tdata) * self.dt + self.tdata.append(t) self.ydata.append(y) self.line.set_data(self.tdata, self.ydata) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy