Skip to content

Commit 8b4bee7

Browse files
authored
Merge pull request #24481 from QuLogic/fix-oscilloscope-drift
Fix floating-point drift in oscilloscope example
2 parents 6c721e9 + 55f5978 commit 8b4bee7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/animation/strip_chart.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ def __init__(self, ax, maxt=2, dt=0.02):
2626

2727
def update(self, y):
2828
lastt = self.tdata[-1]
29-
if lastt > self.tdata[0] + self.maxt: # reset the arrays
29+
if lastt >= self.tdata[0] + self.maxt: # reset the arrays
3030
self.tdata = [self.tdata[-1]]
3131
self.ydata = [self.ydata[-1]]
3232
self.ax.set_xlim(self.tdata[0], self.tdata[0] + self.maxt)
3333
self.ax.figure.canvas.draw()
3434

35-
t = self.tdata[-1] + self.dt
35+
# This slightly more complex calculation avoids floating-point issues
36+
# from just repeatedly adding `self.dt` to the previous value.
37+
t = self.tdata[0] + len(self.tdata) * self.dt
38+
3639
self.tdata.append(t)
3740
self.ydata.append(y)
3841
self.line.set_data(self.tdata, self.ydata)

0 commit comments

Comments
 (0)
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