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

Plot results separately #157

Open
andrisecker opened this issue Nov 26, 2017 · 4 comments
Open

Plot results separately #157

andrisecker opened this issue Nov 26, 2017 · 4 comments
Milestone

Comments

@andrisecker
Copy link

andrisecker commented Nov 26, 2017

Hi @jaidevd,

amazing package, thanks very much!
I might find the answer by locating in the code, but if you could answer that would speed it up:
I was wondering if it's possible to get the computed data and plot the results separately? (eg as a subplot of an other big plot...)

wvd = WignerVilleDistribution(sig)
wvd.run()
# get values from wvd
#wvd.plot(kind="contour", scale="log")  # replace this with ax.plot(...)
@jaidevd
Copy link
Member

jaidevd commented Nov 27, 2017

Hi @andrisecker ,

Sure, so running the run method returns a tuple consisting of (tfr, ts, freqs), which are the time-frequency matrix, the timestamps and frequency samples respectively. You can use these to make your plot any way you like, for example:

wvd = WignerVilleDistribution(sig)
tfr, ts, freqs = wvd.run()
plt.imshow(np.abs(tfr))

Instead of this, you can also pass and ax object to the plot method, and it will draw plot on that ax object, like so:

fig, ax = plt.subplots(nrows=2, ncols=2) # grid of 4 subplots
wvd = WignerVilleDistribution(sig)
wvd.run()
wvd.plot(ax=ax[2, 2])
# This will plot the TFR in the bottom right subplot, leaving the others intact.

(Got this from how pandas does it's plotting)
Note that this second approach hasn't been tested too much. So while you can use the first one easily, feedback on the second approach might be immensely useful.

Thanks,

@andrisecker
Copy link
Author

andrisecker commented Nov 27, 2017

thanks @jaidevd!
So the thing is that I can't use the first to plot the matrix, because I get Segmentation error for imshow (which I also get by calling wvd.plot(kind='cmap') so it might not be the problem of plotting with imshow) but the second approach with the ax arguments seems working with the contour plot (but it's still tricky to format) and I can also recreate the contour plot from tfr, ts, freqs.

I'm having hard time to interpret what I see by using WignerVilleDistribution! According to my PSD analysis I should see ~100 and ~200Hz oscillations, but for me it looks like more than the 2 dominant frequencies on the TFR plot and I'm not convinced that they are present only in the middle of the dataset.
figure

By using Morlet Spectogram the results seem more convincing! This is what people usually use with this kind of data (firing rate of a neuron population) so maybe I just shouldn't try to interpret the first figure....
figure_1

I still have a question for this though: Is there any kind of documentation available about the math behind it (particularly the processing.Scalogram)? Which normalization factor do you apply eg. for the Morlet wavelet?

Thanks!

@jaidevd
Copy link
Member

jaidevd commented Dec 7, 2017

Hi @andrisecker

Sorry for the delay in responding. Yes, in the current form, the heatmaps are difficult to interpret, not just for WVD but even for simpler tools like spectrograms. I'm in the process of revamping the interface a bit so that the distributions are more intuitive. This might take a while to fix, I'll keep updating it here.

Thanks,

@jaidevd
Copy link
Member

jaidevd commented Oct 12, 2018

Coming back to the original issue, I think it is necessary to separate the plotting code from the TFR classes. The .plot() method should still be available, since visualization ought to be tied to the specific TFR being used, but plotting it separately should also be possible, especially in the interest of modularity.

@jaidevd jaidevd added this to the v0.2 Release milestone Jan 11, 2021
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

No branches or pull requests

2 participants