Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55f5978

Browse filesBrowse files
committed
Fix floating-point drift in oscilloscope example
1 parent d17c05f commit 55f5978
Copy full SHA for 55f5978

File tree

Expand file treeCollapse file tree

1 file changed

+5
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-2
lines changed

‎examples/animation/strip_chart.py

Copy file name to clipboardExpand all lines: examples/animation/strip_chart.py
+5-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.