Skip to content

Commit

Permalink
Merge pull request #308 from biggates/bugfix/plot/create_figure
Browse files Browse the repository at this point in the history
bugfix: unable to plot single channel record
  • Loading branch information
briangow authored Jun 21, 2021
2 parents 8c48534 + 227ebcc commit 76eab35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 76eab35

Please sign in to comment.