Skip to content

Commit 3f52669

Browse files
author
Vivek Gopalakrishnan
authored
Update plot.py
1 parent 1ed45ab commit 3f52669

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

wfdb/plot/plot.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
1313
time_units='samples', sig_name=None, sig_units=None,
1414
xlabel=None, ylabel=None, title=None, sig_style=[''],
1515
ann_style=['r*'], ecg_grids=[], figsize=None,
16-
return_fig=False, return_fig_axes=False):
16+
sharex=False, sharey=False, return_fig=False,
17+
return_fig_axes=False):
1718
"""
1819
Subplot individual channels of signals and/or annotations.
1920
@@ -78,6 +79,12 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
7879
also be set to 'all' for all channels. Major grids at 0.5mV, and minor
7980
grids at 0.125mV. All channels to be plotted with grids must have
8081
`sig_units` equal to 'uV', 'mV', or 'V'.
82+
sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
83+
Controls sharing of properties among x (`sharex`) or y (`sharey`) axes:
84+
True or 'all': x- or y-axis will be shared among all subplots.
85+
False or 'none': each subplot x- or y-axis will be independent.
86+
'row': each subplot row will share an x- or y-axis.
87+
'col': each subplot column will share an x- or y-axis.
8188
figsize : tuple, optional
8289
Tuple pair specifying the width, and height of the figure. It is the
8390
'figsize' argument passed into matplotlib.pyplot's `figure` function.
@@ -108,7 +115,7 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
108115
sig_len, n_sig, n_annot, n_subplots = get_plot_dims(signal, ann_samp)
109116

110117
# Create figure
111-
fig, axes = create_figure(n_subplots, figsize)
118+
fig, axes = create_figure(n_subplots, sharex, sharey, figsize)
112119

113120
if signal is not None:
114121
plot_signal(signal, sig_len, n_sig, fs, time_units, sig_style, axes)
@@ -200,7 +207,7 @@ def get_plot_dims(signal, ann_samp):
200207
return sig_len, n_sig, n_annot, max(n_sig, n_annot)
201208

202209

203-
def create_figure(n_subplots, figsize):
210+
def create_figure(n_subplots, sharex, sharey, figsize):
204211
"""
205212
Create the plot figure and subplot axes.
206213
@@ -210,21 +217,23 @@ def create_figure(n_subplots, figsize):
210217
The number of subplots to generate.
211218
figsize : tuple
212219
The figure's width, height in inches.
220+
sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
221+
Controls sharing of properties among x (`sharex`) or y (`sharey`) axes:
222+
True or 'all': x- or y-axis will be shared among all subplots.
223+
False or 'none': each subplot x- or y-axis will be independent.
224+
'row': each subplot row will share an x- or y-axis.
225+
'col': each subplot column will share an x- or y-axis.
213226
214227
Returns
215228
-------
216229
fig : matplotlib plot object
217230
The entire figure that will hold each subplot.
218231
axes : list
219232
The information needed for each subplot.
220-
221233
"""
222-
fig = plt.figure(figsize=figsize)
223-
axes = []
224-
225-
for i in range(n_subplots):
226-
axes.append(fig.add_subplot(n_subplots, 1, i+1))
227-
234+
fig, axes = plt.subplots(
235+
nrows=n_subplots, ncols=1, sharex=sharex, sharey=sharey, figsize=figsize
236+
)
228237
return fig, axes
229238

230239

0 commit comments

Comments
 (0)