Skip to content

Commit

Permalink
Merge pull request #291 from v715/patch-1
Browse files Browse the repository at this point in the history
Update plot.py to include sharex, sharey
  • Loading branch information
Lucas-Mc authored Apr 12, 2021
2 parents 1ed45ab + f6405a8 commit eb53f12
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions wfdb/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
time_units='samples', sig_name=None, sig_units=None,
xlabel=None, ylabel=None, title=None, sig_style=[''],
ann_style=['r*'], ecg_grids=[], figsize=None,
return_fig=False, return_fig_axes=False):
sharex=False, sharey=False, return_fig=False,
return_fig_axes=False):
"""
Subplot individual channels of signals and/or annotations.
Expand Down Expand Up @@ -78,6 +79,10 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
also be set to 'all' for all channels. Major grids at 0.5mV, and minor
grids at 0.125mV. All channels to be plotted with grids must have
`sig_units` equal to 'uV', 'mV', or 'V'.
sharex, sharey : bool, optional
Controls sharing of properties among x (`sharex`) or y (`sharey`) axes.
If True: x- or y-axis will be shared among all subplots.
If False, each subplot x- or y-axis will be independent.
figsize : tuple, optional
Tuple pair specifying the width, and height of the figure. It is the
'figsize' argument passed into matplotlib.pyplot's `figure` function.
Expand Down Expand Up @@ -108,7 +113,7 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
sig_len, n_sig, n_annot, n_subplots = get_plot_dims(signal, ann_samp)

# Create figure
fig, axes = create_figure(n_subplots, figsize)
fig, axes = create_figure(n_subplots, sharex, sharey, figsize)

if signal is not None:
plot_signal(signal, sig_len, n_sig, fs, time_units, sig_style, axes)
Expand Down Expand Up @@ -200,7 +205,7 @@ def get_plot_dims(signal, ann_samp):
return sig_len, n_sig, n_annot, max(n_sig, n_annot)


def create_figure(n_subplots, figsize):
def create_figure(n_subplots, sharex, sharey, figsize):
"""
Create the plot figure and subplot axes.
Expand All @@ -210,21 +215,21 @@ def create_figure(n_subplots, figsize):
The number of subplots to generate.
figsize : tuple
The figure's width, height in inches.
sharex, sharey : bool, optional
Controls sharing of properties among x (`sharex`) or y (`sharey`) axes.
If True: x- or y-axis will be shared among all subplots.
If False, each subplot x- or y-axis will be independent.
Returns
-------
fig : matplotlib plot object
The entire figure that will hold each subplot.
axes : list
The information needed for each subplot.
"""
fig = plt.figure(figsize=figsize)
axes = []

for i in range(n_subplots):
axes.append(fig.add_subplot(n_subplots, 1, i+1))

fig, axes = plt.subplots(
nrows=n_subplots, ncols=1, sharex=sharex, sharey=sharey, figsize=figsize
)
return fig, axes


Expand Down

0 comments on commit eb53f12

Please sign in to comment.