-
Notifications
You must be signed in to change notification settings - Fork 72
[ENH] - Plot updates & extensions #319
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
97fd872
add multi_time_series plot
TomDonoghue b6b7b6e
add & use helper function to checking plot time definition
TomDonoghue 00d119a
add ticks & labels as catchable axis style args
TomDonoghue 974213c
add special case to set minorticks on/off in axis_styler
TomDonoghue e0677b2
add combined ts & psd plot
TomDonoghue edf6da2
fix import
TomDonoghue 63cbf33
udpate description of style_plot
TomDonoghue 45f6f10
add collection styler
TomDonoghue 19effe1
allow for turning off style funcs with None
TomDonoghue 7fbdce1
fix collection styler
TomDonoghue b96650e
fix example
TomDonoghue 235cd7b
fix doctest for checking style args
TomDonoghue 942db13
udpate style management of tight_layout
TomDonoghue 7f24d08
fix plot style doctest
TomDonoghue 0099a6e
round doctests for checking
TomDonoghue cf503c9
add new plots to init
TomDonoghue a31759c
add new plts to API list
TomDonoghue 52e9ec1
fix extra **'s in docs
TomDonoghue c497d1c
drop combined from init due to circular import
TomDonoghue 6ce3df2
drop times from combined plot (& compute internally)
TomDonoghue 6ac7c0f
fix up start_val and ts_range
TomDonoghue b551ef1
add to init & avoid circular imports
TomDonoghue 0189891
tweak times related inputs to plot_combined
TomDonoghue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| """Plotting functions.""" | ||
|
|
||
| from .time_series import plot_time_series, plot_bursts, plot_instantaneous_measure | ||
| from .time_series import (plot_time_series, plot_bursts, plot_instantaneous_measure, | ||
| plot_multi_time_series) | ||
| from .filt import plot_filter_properties, plot_frequency_response, plot_impulse_response | ||
| from .rhythm import plot_swm_pattern, plot_lagged_coherence | ||
| from .spectral import (plot_power_spectra, plot_spectral_hist, | ||
| plot_scv, plot_scv_rs_lines, plot_scv_rs_matrix) | ||
| from .timefrequency import plot_timefrequency | ||
| from .combined import plot_timeseries_and_spectrum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """Plotting functions for plots with combined panels.""" | ||
|
|
||
| import matplotlib.pyplot as plt | ||
|
|
||
| from neurodsp.utils.data import create_times | ||
| from neurodsp.plts.spectral import plot_power_spectra | ||
| from neurodsp.plts.time_series import plot_time_series | ||
| from neurodsp.plts.utils import savefig | ||
|
|
||
| ################################################################################################### | ||
| ################################################################################################### | ||
|
|
||
| @savefig | ||
| def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, times=None, start_val=0., | ||
| spectrum_kwargs=None, ts_kwargs=None, psd_kwargs=None, | ||
| **plt_kwargs): | ||
| """Plot a timeseries together with it's associated power spectrum. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| sig : 1d array | ||
| Time series to plot. | ||
| fs : float | ||
| Sampling rate, in Hz. | ||
| ts_range : list of [float, float], optional | ||
| The time range to restrict the time series to. | ||
| For visualization only - the power spectrum is computed over the entire time series. | ||
| f_range : list of [float, float], optional | ||
| The frequency range to restrict the power spectrum to. | ||
| times : 1d, optional | ||
| Time definition for the time series to be plotted. | ||
| If not provided, times are recomputed from signal length and sampling rate. | ||
| start_val : float, optional, default: 0. | ||
| The starting value for the time definition for the time series. | ||
| Only used if `times` is not provided. | ||
| spectrum_kwargs : dict, optional | ||
| Keyword arguments for computing the power spectrum. | ||
| See `compute_spectrum` for details. | ||
| ts_kwargs : dict, optional | ||
| Keyword arguments for customizing the time series plot. | ||
| psd_kwargs : dict, optional | ||
| Keyword arguments for customizing the power spectrum plot. | ||
| **plt_kwargs | ||
| Keyword arguments for customizing the plots. | ||
| These arguments are passed to both plot axes. | ||
| """ | ||
|
|
||
| # Import spectal functions locally to avoid circular imports | ||
| from neurodsp.spectral import compute_spectrum | ||
| from neurodsp.spectral.utils import trim_spectrum | ||
|
|
||
| # Allow for defining color as 'color' (since one line per plot), rather than 'colors' | ||
| if 'color' in plt_kwargs: | ||
| plt_kwargs['colors'] = plt_kwargs.pop('color') | ||
|
|
||
| # Default to drawing both plots in same color (otherwise ts is black, psd is blue) | ||
| if 'colors' not in plt_kwargs: | ||
| psd_kwargs = {} if psd_kwargs is None else psd_kwargs | ||
| if 'colors' not in psd_kwargs: | ||
| psd_kwargs['colors'] = 'black' | ||
|
|
||
| fig = plt.figure(figsize=plt_kwargs.pop('figsize', None)) | ||
| ax1 = fig.add_axes([0.0, 0.6, 1.3, 0.5]) | ||
| ax2 = fig.add_axes([1.5, 0.6, 0.6, 0.5]) | ||
|
|
||
| if not times: | ||
| times = create_times(len(sig) / fs, fs, start_val=start_val) | ||
| if ts_range: | ||
| ts_kwargs['xlim'] = ts_range | ||
| plot_time_series(times, sig, ax=ax1, **plt_kwargs, | ||
| **ts_kwargs if ts_kwargs else {}) | ||
|
|
||
| freqs, psd = compute_spectrum(sig, fs, **spectrum_kwargs if spectrum_kwargs else {}) | ||
| if f_range: | ||
| freqs, psd = trim_spectrum(freqs, psd, f_range) | ||
| plot_power_spectra(freqs, psd, ax=ax2, **plt_kwargs, | ||
| **psd_kwargs if psd_kwargs else {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.