Adaptive waveplot
See original GitHub issueIs your feature request related to a problem? Please describe.
display.waveplot
works by downsampling the input waveform to get an amplitude envelope, rather than the raw samples.
This is great when we want a big-picture view of a long signal, but it’s pretty lousy when we’re looking at a signal close up. The max_points
parameter sets a threshold of sample counts, below which the raw signal is displayed.
The problem is that there’s no easy way to switch between the two modes based on the actual display limits of plot in question. For example, it’d be nice to be able to just waveplot
some data, set the axis limits later, and have the plot decide dynamically whether to show the aggregated envelope or the raw samples. Even better, for interactive backends (ipympl, qt), a user could zoom in or out, and the plot should update automatically.
Describe the solution you’d like
The matplotlib example gallery shows how to do this kind of thing using a callback for whenever the display limits change. The example there isn’t perfect: it recomputes the downsampled signal on any limit change, including panning (not just zooming), so it’s likely pretty slow. But I think we could adapt it to be more efficient.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
Hi Brian (@bmcfee), If this is still open, I could take a crack at it. I recently had to solve a similar problem.
Looks like multi-plotting actually does work!
when zoomed out (envelope mode):
and then zoomed in (samples mode):
And here’s a video embed of it running interactively:
https://user-images.githubusercontent.com/1190540/118262220-94cad100-b482-11eb-8131-ff875cf8797b.mp4
At this point I’m pretty happy with the implementation. There are still a few rough edges to work out, mostly around how kwargs are handled for the different artists, and how axes limits are set. I’ll try to smooth these out in the coming days and then open a PR.