@@ -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,10 @@ 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, optional
83+ Controls sharing of properties among x (`sharex`) or y (`sharey`) axes.
84+ If True: x- or y-axis will be shared among all subplots.
85+ If False, each subplot x- or y-axis will be independent.
8186 figsize : tuple, optional
8287 Tuple pair specifying the width, and height of the figure. It is the
8388 'figsize' argument passed into matplotlib.pyplot's `figure` function.
@@ -108,7 +113,7 @@ def plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None,
108113 sig_len , n_sig , n_annot , n_subplots = get_plot_dims (signal , ann_samp )
109114
110115 # Create figure
111- fig , axes = create_figure (n_subplots , figsize )
116+ fig , axes = create_figure (n_subplots , sharex , sharey , figsize )
112117
113118 if signal is not None :
114119 plot_signal (signal , sig_len , n_sig , fs , time_units , sig_style , axes )
@@ -200,7 +205,7 @@ def get_plot_dims(signal, ann_samp):
200205 return sig_len , n_sig , n_annot , max (n_sig , n_annot )
201206
202207
203- def create_figure (n_subplots , figsize ):
208+ def create_figure (n_subplots , sharex , sharey , figsize ):
204209 """
205210 Create the plot figure and subplot axes.
206211
@@ -210,21 +215,21 @@ def create_figure(n_subplots, figsize):
210215 The number of subplots to generate.
211216 figsize : tuple
212217 The figure's width, height in inches.
218+ sharex, sharey : bool, optional
219+ Controls sharing of properties among x (`sharex`) or y (`sharey`) axes.
220+ If True: x- or y-axis will be shared among all subplots.
221+ If False, each subplot x- or y-axis will be independent.
213222
214223 Returns
215224 -------
216225 fig : matplotlib plot object
217226 The entire figure that will hold each subplot.
218227 axes : list
219228 The information needed for each subplot.
220-
221229 """
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-
230+ fig , axes = plt .subplots (
231+ nrows = n_subplots , ncols = 1 , sharex = sharex , sharey = sharey , figsize = figsize
232+ )
228233 return fig , axes
229234
230235
0 commit comments