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

bugfix: unable to plot single channel record #308

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import wfdb
from wfdb.plot import plot
import unittest

class TestPlot(unittest.TestCase):

def test_get_plot_dims(self):
sampfrom = 0
sampto = 3000
record = wfdb.rdrecord('sample-data/100', physical=True, sampfrom=sampfrom, sampto=sampto)
ann = wfdb.rdann('sample-data/100', 'atr', sampfrom=sampfrom, sampto=sampto)
sig_len, n_sig, n_annot, n_subplots = plot.get_plot_dims(signal=record.p_signal, ann_samp=[ann.sample])

assert sig_len == sampto - sampfrom
assert n_sig == record.n_sig
assert n_annot == 1
assert n_subplots == record.n_sig

def test_create_figure_single_subplots(self):
n_subplots = 1
fig, axes = plot.create_figure(n_subplots, sharex=True, sharey=True, figsize=None)
assert fig is not None
assert axes is not None
assert len(axes) == n_subplots

def test_create_figure_multiple_subplots(self):
n_subplots = 5
fig, axes = plot.create_figure(n_subplots, sharex=True, sharey=True, figsize=None)
assert fig is not None
assert axes is not None
assert len(axes) == n_subplots
2 changes: 2 additions & 0 deletions wfdb/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def create_figure(n_subplots, sharex, sharey, figsize):
fig, axes = plt.subplots(
nrows=n_subplots, ncols=1, sharex=sharex, sharey=sharey, figsize=figsize
)
if n_subplots == 1:
axes = [axes]
return fig, axes


Expand Down