Skip to content

Align signals horizontally in plot_wfdb (if possible) #390

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 2 commits into from
Jun 24, 2022
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
25 changes: 24 additions & 1 deletion wfdb/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,14 @@ def plot_wfdb(
record=None,
annotation=None,
plot_sym=False,
time_units="samples",
time_units="seconds",
title=None,
sig_style=[""],
ann_style=["r*"],
ecg_grids=[],
figsize=None,
return_fig=False,
sharex="auto",
):
"""
Subplot individual channels of a WFDB record and/or annotation.
Expand Down Expand Up @@ -917,6 +918,12 @@ def plot_wfdb(
'figsize' argument passed into matplotlib.pyplot's `figure` function.
return_fig : bool, optional
Whether the figure is to be returned as an output argument.
sharex : bool or 'auto', optional
Whether the X axis should be shared between all subplots. If set
to True, then all signals will be aligned with each other. If set
to False, then each subplot can be panned/zoomed independently. If
set to 'auto' (default), then the X axis will be shared unless
record is multi-frequency and the time units are set to 'samples'.

Returns
-------
Expand Down Expand Up @@ -954,6 +961,21 @@ def plot_wfdb(
else:
sampling_freq = None

if sharex == "auto":
# If the sampling frequencies are equal, or if we are using
# hours/minutes/seconds as the time unit, then share the X axes so
# that the channels are synchronized. If time units are 'samples'
# and sampling frequencies are not uniform, then sharing X axes
# doesn't work and may even be misleading.
if (
time_units == "samples"
and isinstance(sampling_freq, list)
and any(f != sampling_freq[0] for f in sampling_freq)
):
sharex = False
else:
sharex = True

if annotation and annotation.fs is not None:
ann_freq = annotation.fs
elif record:
Expand All @@ -977,6 +999,7 @@ def plot_wfdb(
return_fig=return_fig,
sampling_freq=sampling_freq,
ann_freq=ann_freq,
sharex=sharex,
)


Expand Down