2424@savefig
2525@style_plot
2626@check_dependency (plt , 'matplotlib' )
27- def plot_spectra (freqs , power_spectra , log_freqs = False , log_powers = False ,
27+ def plot_spectra (freqs , power_spectra , log_freqs = False , log_powers = False , freq_range = None ,
2828 colors = None , labels = None , ax = None , ** plot_kwargs ):
2929 """Plot one or multiple power spectra.
3030
@@ -38,21 +38,27 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False,
3838 Whether to plot the frequency axis in log spacing.
3939 log_powers : bool, optional, default: False
4040 Whether to plot the power axis in log spacing.
41+ freq_range : list of [float, float], optional
42+ Frequency range to plot, defined in linear space.
4143 colors : list of str, optional, default: None
4244 Line colors of the spectra.
4345 labels : list of str, optional, default: None
4446 Legend labels for the spectra.
4547 ax : matplotlib.Axes, optional
4648 Figure axes upon which to plot.
4749 **plot_kwargs
48- Keyword arguments to pass into the ``style_plot`` .
50+ Additional plot related keyword arguments .
4951 """
5052
5153 ax = check_ax (ax , plot_kwargs .pop ('figsize' , PLT_FIGSIZES ['spectral' ]))
5254
5355 # Create the plot
5456 plot_kwargs = check_plot_kwargs (plot_kwargs , {'linewidth' : 2.0 })
5557
58+ # Check for frequency range input, and log if x-axis is in log space
59+ if freq_range is not None :
60+ freq_range = np .log10 (freq_range ) if log_freqs else freq_range
61+
5662 # Make inputs iterable if need to be passed multiple times to plot each spectrum
5763 plt_powers = np .reshape (power_spectra , (1 , - 1 )) if np .ndim (power_spectra ) == 1 else \
5864 power_spectra
@@ -63,7 +69,7 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False,
6369 labels = repeat (labels ) if not isinstance (labels , list ) else cycle (labels )
6470 colors = repeat (colors ) if not isinstance (colors , list ) else cycle (colors )
6571
66- # Plot
72+ # Plot power spectra, looping across all spectra to plot
6773 for freqs , powers , color , label in zip (plt_freqs , plt_powers , colors , labels ):
6874
6975 # Set plot data, logging if requested, and collect color, if absent
@@ -74,6 +80,8 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False,
7480
7581 ax .plot (freqs , powers , label = label , ** plot_kwargs )
7682
83+ ax .set_xlim (freq_range )
84+
7785 style_spectrum_plot (ax , log_freqs , log_powers )
7886
7987
@@ -102,7 +110,8 @@ def plot_spectra_shading(freqs, power_spectra, shades, shade_colors='r',
102110 ax : matplotlib.Axes, optional
103111 Figure axes upon which to plot.
104112 **plot_kwargs
105- Keyword arguments to pass into :func:`~.plot_spectra`.
113+ Additional plot related keyword arguments.
114+ This can include additional inputs into :func:`~.plot_spectra`.
106115
107116 Notes
108117 -----
@@ -152,7 +161,7 @@ def plot_spectra_yshade(freqs, power_spectra, shade='std', average='mean', scale
152161 ax : matplotlib.Axes, optional
153162 Figure axes upon which to plot.
154163 **plot_kwargs
155- Keyword arguments to be passed to `plot_spectra` or to the plot call .
164+ Additional plot related keyword arguments .
156165 """
157166
158167 if (isinstance (shade , str ) or isfunction (shade )) and power_spectra .ndim != 2 :
0 commit comments