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

Open vmax and vmin access in yasa.plot_spectrogram() #73

Closed
matiasandina opened this issue Jun 7, 2022 · 3 comments · Fixed by #75
Closed

Open vmax and vmin access in yasa.plot_spectrogram() #73

matiasandina opened this issue Jun 7, 2022 · 3 comments · Fixed by #75
Assignees
Labels
enhancement 🚧 New feature or request

Comments

@matiasandina
Copy link
Contributor

It's not always useful, but sometimes you want to plot different channels on a common scale.
I think plot_spectrogram() could have vmax=None and vmin=None and, if supplied, they would overrule the normalization of the colormap.

It might be that this can be done once the spectrogram is but I'm not so fluent in matplotlib to do so.

@raphaelvallat raphaelvallat self-assigned this Jun 8, 2022
@raphaelvallat raphaelvallat added the enhancement 🚧 New feature or request label Jun 8, 2022
@raphaelvallat
Copy link
Owner

Hi @matiasandina,

Good idea. It should be pretty straightforward to implement. Do you want to submit a PR? Or I'll work on it for the next release.

Thanks,
Raphael

@matiasandina
Copy link
Contributor Author

matiasandina commented Jun 8, 2022 via email

@matiasandina
Copy link
Contributor Author

Turns out I needed it myself and it was way easier than what I thought. Will submit a PR soon

from io import BytesIO
import numpy as np
import requests
import local version of plot_spectrogram

r = requests.get('https://github.com/raphaelvallat/yasa/raw/master/notebooks/data_full_6hrs_100Hz_Cz%2BFz%2BPz.npz', stream=True)
npz = np.load(BytesIO(r.raw.read()))
data = npz.get('data')[0, :]
sf = 100
fig = plot_spectrogram(data, sf)

image

fig2 = plot_spectrogram(data, sf, vmin=-50, vmax=100)

image

Trying to test it for failure

fig3 = plot_spectrogram(data, sf, vmin=-50, vmax='asdf')

Results in

113 assert fmax < sf / 2, 'fmax must be less than Nyquist (sf / 2).'
    114 assert isinstance(vmin, (int, float, type(None))), 'vmin must be int, float, or None.'
--> 115 assert isinstance(vmax, (int, float, type(None))), 'vmax must be int, float, or None.'
    116 if vmin is not None:
    117   assert isinstance(vmax, (int, float)), 'vmax must be int or float if vmin is provided'

matiasandina added a commit to matiasandina/yasa that referenced this issue Jun 9, 2022
@raphaelvallat raphaelvallat linked a pull request Jun 9, 2022 that will close this issue
raphaelvallat added a commit that referenced this issue Jul 19, 2022
* adding vmax vmin functionality with minimal tests #73

* Black formatting

* Update changelog + unit tests

Co-authored-by: Raphael Vallat <raphaelvallat9@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🚧 New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants