Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #24481 on branch v3.6.x (Fix floating-point drift in oscilloscope example) #24485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/animation/strip_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down