Skip to content

Add xlabel and ylabel to plot_wfdb - #670

Merged
tompollard merged 1 commit into
mainfrom
plot-wfdb-axis-labels
Nov 23, 2026
Merged

tompollard merged 1 commit into
mainfrom
plot-wfdb-axis-labels

Conversation

@tompollard

Copy link
Copy Markdown
Member

Fixes #276.

plot_wfdb now takes xlabel and ylabel, lists with a label for each channel, and passes them to plot_items, which already supported them. Without them the labels are as before: the signal names and units on the y axes, and time/second (or the chosen unit) on the bottom x axis. The new arguments come last, so calls that pass arguments by position are unaffected.

wfdb.plot_wfdb(record, xlabel=["", "Time (s)"], ylabel=["Lead II (mV)", "Lead V5 (mV)"])

This also fixes xlabel in plot_items, which has never worked: it checked the number of labels against signal.shape[1] after signal had become a list of channels, so it raised AttributeError: 'list' object has no attribute 'shape'. It now checks against the number of subplots, as ylabel does.

Testing

  • New tests for the default labels, custom labels in plot_wfdb, and xlabel in plot_items. The last two fail on main.
  • pytest -m "not network": all pass. Ruff and the docs build pass.

@tompollard 🟥 red 🦥 sloth · aspen

plot_wfdb takes lists of x and y labels, passed to plot_items, to replace
the default axis labels. plot_items checked the number of x labels against
signal.shape, after signal had become a list of channels, so it failed with
an AttributeError whenever xlabel was given. Check against the number of
subplots, as for ylabel.

Fixes #276.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed 705e4b5. The custom x and y labels work for signal plots and annotation-only plots, and the default labels remain intact. I found no actionable issues. All 13 focused plotting tests pass; the remaining CI jobs are still running. Looks good to merge once they pass.

@tompollard
tompollard merged commit 92f9a3b into main Nov 23, 2026
18 checks passed
@tompollard
tompollard deleted the plot-wfdb-axis-labels branch November 23, 2026 23:01
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.

Allow for custom xlabel and ylabel in plot_wfdb

1 participant