8000 Doc yinleon rebase by tacaswell · Pull Request #8860 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Doc yinleon rebase #8860

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
merged 7 commits into from
Jul 15, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DOC: tweak re sampling demo to use different resampling method
Fixed target number of points instead of fixed data reduction.
  • Loading branch information
tacaswell committed Jul 11, 2017
commit e3429cde480dd2aee9f7350e45cda74e69dd2aa2
29 changes: 19 additions & 10 deletions examples/event_handling/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
Resampling Data
===============


Downsampling lowers the sample rate or sample size of a signal. In
this tutorial, the signal is downsampled when the plot is adjusted
through dragging and zooming.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... except that the example is completely broken (try it). It should either be fixed or removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does what it claims, but in a weird way. It always down-samples to every 5th point but also clips the data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re worked this a bit.

It works on zoom, but not pan which seems like a bug Mpl, not in the example.


"""

import numpy as np
Expand All @@ -19,18 +17,28 @@ class DataDisplayDownsampler(object):
def __init__(self, xdata, ydata):
self.origYData = ydata
self.origXData = xdata
self.ratio = 5
self.max_points = 50
self.delta = xdata[-1] - xdata[0]

def downsample(self, xstart, xend):
# Very simple downsampling that takes the points within the range
# and picks every Nth point
# get the points in the view range
mask = (self.origXData > xstart) & (self.origXData < xend)
xdata = self.origXData[mask]
xdata = xdata[::self.ratio]
# dilate the mask by one to catch the points just outside
# of the view range to not truncate the line
mask = np.convolve([1, 1], mask, mode='same').astype(bool)
# sort out how many points to drop
ratio = max(np.sum(mask) // self.max_points, 1)

# mask data
xdata = self.origXData[mask]
ydata = self.origYData[mask]
ydata = ydata[::self.ratio]

# downsample data
xdata = xdata[::ratio]
ydata = ydata[::ratio]

print("using {} of {} visible points".format(
len(ydata), np.sum(mask)))

return xdata, ydata

Expand All @@ -43,8 +51,9 @@ def update(self, ax):
self.line.set_data(*self.downsample(xstart, xend))
ax.figure.canvas.draw_idle()


# Create a signal
xdata = np.linspace(16, 365, 365-16)
xdata = np.linspace(16, 365, (365-16)*4)
ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127)

d = DataDisplayDownsampler(xdata, ydata)
Expand All @@ -57,5 +66,5 @@ def update(self, ax):

# Connect for changing the view limits
ax.callbacks.connect('xlim_changed', d.update)

ax.set_xlim(16, 365)
plt.show()
0