Skip to content
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

Align signals horizontally in plot_wfdb (if possible) #390

Merged
merged 2 commits into from
Jun 24, 2022
Merged

Conversation

bemoody
Copy link
Collaborator

@bemoody bemoody commented Jun 8, 2022

In plot_wfdb, add an argument sharex which controls whether X axes are shared between subplots.

(This means that multiple channels will always appear time-aligned with each other, even if one channel starts or ends with a block of NaNs. It also means that if you use the pan/zoom buttons to navigate, the channels will stay aligned with each other.)

sharex=True is generally desirable behavior; however, if the time units are sample numbers and the record is multi-frequency, then it's not possible (AFAICT) with matplotlib to have the axes synchronized while displaying different units on different subplots. So we disable sharex by default in that case.

Finally, plot_wfdb will use time_units="seconds" by default, which I think is useful because it's consistent (across databases) and familiar.

(original pull request description follows)

A few changes to improve plotting of multiple channels and multiple frequencies:

  • For plot_items and various internal functions, rename the fs argument to frame_freq so it is (perhaps) more clear what it means for multi-frequency data. (I'm still not completely satisfied and think plot_items is harder to use than it needs to be.)

  • Allow specifying time_units="frames" as an alternative to "samples", "seconds", etc.

  • The big change: plot_wfdb uses sharex=True. This means that multiple channels will always appear time-aligned with each other, even if one channel starts or ends with a block of NaNs. It also means that if you use the pan/zoom buttons to navigate, the channels will stay aligned with each other.

  • plot_wfdb will use time_units="seconds" by default, which I think is useful because it's consistent (across databases) and familiar.

(fixes issue #373)

@bemoody
Copy link
Collaborator Author

bemoody commented Jun 8, 2022

Whoops, fixed a typo.

@bemoody bemoody mentioned this pull request Jun 10, 2022
@@ -121,7 +121,7 @@ def plot_items(
signal=None,
ann_samp=None,
ann_sym=None,
fs=None,
frame_freq=None,
Copy link
Member

Choose a reason for hiding this comment

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

Demo 6 in demo.ipynb uses the old name.

@@ -217,11 +216,11 @@ def plot_items(
sampling_freq : number or sequence, optional
The sampling frequency or frequencies of the signals. If this is a
list, it must have the same length as the number of channels. If
unspecified, defaults to `fs`.
unspecified, defaults to `frame_freq`.
Copy link
Member

Choose a reason for hiding this comment

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

Having these two parameters is rather confusing. Can you explain why both sampling_freq and frame_freq are both needed?

@bemoody
Copy link
Collaborator Author

bemoody commented Jun 15, 2022 via email

@cx1111
Copy link
Member

cx1111 commented Jun 22, 2022

Yea, let's fix the frame_freq and fs issue separately. I propose:

  1. Use seconds by default in plot_wfdb
  2. Add a sharex parameter in plot_wfdb that can be:
    • "auto" (default): True, except when the signal is multi-frequency and units are set to samples.
    • True
    • False

Benjamin Moody added 2 commits June 24, 2022 14:56
This argument allows the caller to specify whether the horizontal axes
should be synchronized across all channels (subplots) in a plot.

In general, this behavior is desirable as it lets the viewer see the
temporal relationship between channels.  However, in the case where
the record is multi-frequency *and* we are displaying sample numbers
on the horizontal axis, matplotlib unfortunately does not appear to
have a way to synchronize the axes automatically.

Therefore, in the default "auto" case, enable X sharing as long as the
time units for all channels are the same.
@bemoody bemoody changed the title Improve time units in plot_wfdb, and use sharex=True Align signals horizontally in plot_wfdb (if possible) Jun 24, 2022
Copy link
Member

@cx1111 cx1111 left a comment

Choose a reason for hiding this comment

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

Nice!

@bemoody bemoody merged commit a0d8d86 into main Jun 24, 2022
@bemoody bemoody deleted the plot-sharex branch June 24, 2022 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants