Skip to content

Commit 76eab35

Browse files
authored
Merge pull request MIT-LCP#308 from biggates/bugfix/plot/create_figure
bugfix: unable to plot single channel record
2 parents 8c48534 + 227ebcc commit 76eab35

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/test_plot.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import wfdb
2+
from wfdb.plot import plot
3+
import unittest
4+
5+
class TestPlot(unittest.TestCase):
6+
7+
def test_get_plot_dims(self):
8+
sampfrom = 0
9+
sampto = 3000
10+
record = wfdb.rdrecord('sample-data/100', physical=True, sampfrom=sampfrom, sampto=sampto)
11+
ann = wfdb.rdann('sample-data/100', 'atr', sampfrom=sampfrom, sampto=sampto)
12+
sig_len, n_sig, n_annot, n_subplots = plot.get_plot_dims(signal=record.p_signal, ann_samp=[ann.sample])
13+
14+
assert sig_len == sampto - sampfrom
15+
assert n_sig == record.n_sig
16+
assert n_annot == 1
17+
assert n_subplots == record.n_sig
18+
19+
def test_create_figure_single_subplots(self):
20+
n_subplots = 1
21+
fig, axes = plot.create_figure(n_subplots, sharex=True, sharey=True, figsize=None)
22+
assert fig is not None
23+
assert axes is not None
24+
assert len(axes) == n_subplots
25+
26+
def test_create_figure_multiple_subplots(self):
27+
n_subplots = 5
28+
fig, axes = plot.create_figure(n_subplots, sharex=True, sharey=True, figsize=None)
29+
assert fig is not None
30+
assert axes is not None
31+
assert len(axes) == n_subplots

wfdb/plot/plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def create_figure(n_subplots, sharex, sharey, figsize):
230230
fig, axes = plt.subplots(
231231
nrows=n_subplots, ncols=1, sharex=sharex, sharey=sharey, figsize=figsize
232232
)
233+
if n_subplots == 1:
234+
axes = [axes]
233235
return fig, axes
234236

235237

0 commit comments

Comments
 (0)