Skip to content

Update plot.py to include sharex, sharey #291

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

Merged
merged 3 commits into from
Apr 12, 2021
Merged
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
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