|
19 | 19 | ################################################################################################### |
20 | 20 | ################################################################################################### |
21 | 21 |
|
22 | | -@check_dependency(plt, 'matplotlib') |
23 | | -def plot_spectrum(freqs, power_spectrum, log_freqs=False, log_powers=False, |
24 | | - ax=None, plot_style=style_spectrum_plot, **plot_kwargs): |
25 | | - """Plot a power spectrum. |
26 | | -
|
27 | | - Parameters |
28 | | - ---------- |
29 | | - freqs : 1d array |
30 | | - Frequency values, to be plotted on the x-axis. |
31 | | - power_spectrum : 1d array |
32 | | - Power values, to be plotted on the y-axis. |
33 | | - log_freqs : bool, optional, default: False |
34 | | - Whether to plot the frequency axis in log spacing. |
35 | | - log_powers : bool, optional, default: False |
36 | | - Whether to plot the power axis in log spacing. |
37 | | - ax : matplotlib.Axes, optional |
38 | | - Figure axis upon which to plot. |
39 | | - plot_style : callable, optional, default: style_spectrum_plot |
40 | | - A function to call to apply styling & aesthetics to the plot. |
41 | | - **plot_kwargs |
42 | | - Keyword arguments to be passed to the plot call. |
43 | | - """ |
44 | | - |
45 | | - ax = check_ax(ax, plot_kwargs.pop('figsize', PLT_FIGSIZES['spectral'])) |
46 | | - |
47 | | - # Set plot data & labels, logging if requested |
48 | | - plt_freqs = np.log10(freqs) if log_freqs else freqs |
49 | | - plt_powers = np.log10(power_spectrum) if log_powers else power_spectrum |
50 | | - |
51 | | - # Create the plot |
52 | | - plot_kwargs = check_plot_kwargs(plot_kwargs, {'linewidth' : 2.0}) |
53 | | - ax.plot(plt_freqs, plt_powers, **plot_kwargs) |
54 | | - |
55 | | - check_n_style(plot_style, ax, log_freqs, log_powers) |
56 | | - |
57 | 22 |
|
58 | 23 | @check_dependency(plt, 'matplotlib') |
59 | 24 | def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False, labels=None, |
@@ -82,51 +47,28 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False, labels |
82 | 47 |
|
83 | 48 | ax = check_ax(ax, plot_kwargs.pop('figsize', PLT_FIGSIZES['spectral'])) |
84 | 49 |
|
85 | | - # Make inputs iterable if need to be passed multiple times to plot each spectrum |
86 | | - freqs = repeat(freqs) if isinstance(freqs, np.ndarray) and freqs.ndim == 1 else freqs |
87 | | - labels = repeat(labels) if not isinstance(labels, list) else labels |
88 | | - |
89 | | - for freq, power_spectrum, label in zip(freqs, power_spectra, labels): |
90 | | - plot_spectrum(freq, power_spectrum, log_freqs, log_powers, label=label, |
91 | | - plot_style=None, ax=ax, **plot_kwargs) |
92 | | - |
93 | | - check_n_style(plot_style, ax, log_freqs, log_powers) |
94 | | - |
| 50 | + # Create the plot |
| 51 | + plot_kwargs = check_plot_kwargs(plot_kwargs, {'linewidth' : 2.0}) |
95 | 52 |
|
96 | | -@check_dependency(plt, 'matplotlib') |
97 | | -def plot_spectrum_shading(freqs, power_spectrum, shades, shade_colors='r', add_center=False, |
98 | | - ax=None, plot_style=style_spectrum_plot, **plot_kwargs): |
99 | | - """Plot a power spectrum with a shaded frequency region (or regions). |
| 53 | + # Make inputs iterable if need to be passed multiple times to plot each spectrum |
| 54 | + plt_powers = np.reshape(power_spectra, (1, -1)) if np.ndim(power_spectra) == 1 else \ |
| 55 | + power_spectra |
| 56 | + plt_freqs = repeat(freqs) if isinstance(freqs, np.ndarray) and freqs.ndim == 1 else freqs |
100 | 57 |
|
101 | | - Parameters |
102 | | - ---------- |
103 | | - freqs : 1d array |
104 | | - Frequency values, to be plotted on the x-axis. |
105 | | - power_spectrum : 1d array |
106 | | - Power values, to be plotted on the y-axis. |
107 | | - shades : list of [float, float] or list of list of [float, float] |
108 | | - Shaded region(s) to add to plot, defined as [lower_bound, upper_bound]. |
109 | | - shade_colors : str or list of string |
110 | | - Color(s) to plot shades. |
111 | | - add_center : bool, optional, default: False |
112 | | - Whether to add a line at the center point of the shaded regions. |
113 | | - ax : matplotlib.Axes, optional |
114 | | - Figure axes upon which to plot. |
115 | | - plot_style : callable, optional, default: style_spectrum_plot |
116 | | - A function to call to apply styling & aesthetics to the plot. |
117 | | - **plot_kwargs |
118 | | - Keyword arguments to be passed to the plot call. |
119 | | - """ |
| 58 | + # Set labels |
| 59 | + labels = plot_kwargs.pop('label') if 'label' in plot_kwargs.keys() and labels is None else labels |
| 60 | + labels = repeat(labels) if not isinstance(labels, list) else labels |
120 | 61 |
|
121 | | - ax = check_ax(ax, plot_kwargs.pop('figsize', PLT_FIGSIZES['spectral'])) |
| 62 | + # Plot |
| 63 | + for freqs, powers, label in zip(plt_freqs, plt_powers, labels): |
122 | 64 |
|
123 | | - plot_spectrum(freqs, power_spectrum, plot_style=None, ax=ax, **plot_kwargs) |
| 65 | + # Set plot data & labels, logging if requested |
| 66 | + freqs = np.log10(freqs) if log_freqs else freqs |
| 67 | + powers = np.log10(powers) if log_powers else powers |
124 | 68 |
|
125 | | - add_shades(ax, shades, shade_colors, add_center, plot_kwargs.get('log_freqs', False)) |
| 69 | + ax.plot(freqs, powers, label=label, **plot_kwargs) |
126 | 70 |
|
127 | | - check_n_style(plot_style, ax, |
128 | | - plot_kwargs.get('log_freqs', False), |
129 | | - plot_kwargs.get('log_powers', False)) |
| 71 | + check_n_style(plot_style, ax, log_freqs, log_powers) |
130 | 72 |
|
131 | 73 |
|
132 | 74 | @check_dependency(plt, 'matplotlib') |
|
0 commit comments