Skip to content
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

[ENH] - Plotting updates #343

Merged
merged 18 commits into from
Feb 4, 2025
Merged

[ENH] - Plotting updates #343

merged 18 commits into from
Feb 4, 2025

Conversation

TomDonoghue
Copy link
Member

@TomDonoghue TomDonoghue commented Nov 30, 2024

This PR updates and extends some plotting code. It adds to neurodsp some code I developed in the AperiodicHistory project, which I think are general enough to be added her.

Main updates:

  • Create a new prepare_multi_plot which consolidates the same process we had in multiple places for supporting plots that may (or may not) have multiple inputs (e.g. plotting multiple spectra on the same plot)
  • Adds a new plot_autocorr plot
  • Adds a new plot_spectra_3d plot

@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Nov 30, 2024
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Nov 30, 2024
@TomDonoghue TomDonoghue changed the title [WIP] - Plotting updates [ENH] - Plotting updates Dec 3, 2024
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Dec 3, 2024
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Dec 5, 2024
Copy link
Member

@ryanhammonds ryanhammonds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!


@savefig
@style_plot
def plot_autocorr(timepoints, autocorrs, labels=None, colors=None, ax=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thought here is whether to include it in aperiodic.py or somewhere else, since acf isn't restricted to aperiodic signals.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh.... agreed. I wasn't sure where to put it, but since we already have neurodsp/aperiodic/autocorr as the home of the function to compute autocorrelation, this seemed like the most consistent spot for the plot function. I don't know what a better name / place for these things is - so unless we want to re-org, move both I think this works best for now?

... 'sim_bursty_oscillation' : {'freq': 10}})
>>> freqs1, powers1 = compute_spectrum(sig1, fs=500)
>>> freqs2, powers2 = compute_spectrum(sig2, fs=500)
>>> plot_spectra_3D([freqs1, freqs2], [powers1, powers2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the z-axis label is cutoff when I copy/paste the example into a notebook. I tried plt.tight_layout() but it gave an error about the size of the fig not having large enough margins. Maybe a solution would be to add an ax or fig kwarg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, this seems to be an issue with how jupyter notebooks do inline plotting:
matplotlib/matplotlib#28117

When saving out, the figure looks fine, so I don't think we are messing up the plot per se. I'm not sure if there's an action item here - I don't think we want to overtune too much to address a quirk in notebooks.

More broadly, I do think it makes sense to add more access to ax / fig - so I've added a check_ax_3D that will allow for managing / specifying 3D axes.

Also, it seems with the current notebook quirk, changing the zoom can fix the render (https://stackoverflow.com/questions/77577613/matplotlib-3d-plot-z-label-cut-off), so, for example the following make the whole plot visible: plt.gca().set_box_aspect(None, zoom=0.80)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an argument to plot_spectra_3d to be able to pass in a zoom argument, so now in the notebook case one can set the scaling directly as wanted when defining the plot

neurodsp/plts/spectral.py Outdated Show resolved Hide resolved
neurodsp/plts/utils.py Outdated Show resolved Hide resolved
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Dec 18, 2024
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Feb 2, 2025
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Feb 4, 2025
@TomDonoghue TomDonoghue merged commit 1e7959a into main Feb 4, 2025
10 checks passed
@neurodsp-tools neurodsp-tools deleted a comment from codecov bot Feb 4, 2025
@TomDonoghue TomDonoghue deleted the mlplts branch February 4, 2025 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants