contour() function plots with a solid background (and not a transparent background, which is desired)

Dear matlab,
I'm plotting a colored spectrogram with contourf().
Then, I would like to plot statistics on top of this plot by adding a solid line, outlining the regions of statistically significance difference.
In the past, this was achieved by 'hold on' and plotting contour() 'on top of' the other contour plot. (code below)
However, now the second contour plot does plot the soline line circumscribing stat-sig different data BUT the background is a solid color and it overrides/sits on top of the first contoru plot and I can't see the original spectrogram (its all one color purple). Please help. code below. Thanks much in advance.
%%
phas_freqs = 1:1:20;
ampl_freqs = 1:2:70;
% modindex_comodulogram = 20x35 double matrix of numbers
% z_modulation = 20x35 double matrix of Z-VALUES OF THE modindex_comodulogram
figure(8), clf
contourf(phas_freqs,ampl_freqs,modindex_comodulogram',40,'linecolor','none');
hold on
contour(phas_freqs,ampl_freqs,logical(z_modulation)',1,'linecolor','m','LineWidth',3);
%%%%%%%%%%%%%%%%%%%%%%%%%%
I PLOTTED BOTH IN SEPARATE PLOTS BELOW.
I WOULD LIKE TO PUT THE LINE PLOT 'ON TOP' OF THE SPECTROGRAM IN ONE PLOT. please help!

 Accepted Answer

Perhaps something like this —
[X,Y,Z] = peaks(50);
figure
surf(X,Y,Z, 'EdgeColor','none')
hold on
contour3(X, Y, Z, 'Color','m', 'LineWidth',2)
hold off
view(0, 90)
colormap(turbo)
Expedriment with this code and your data ato get the desired result.
.

8 Comments

Thanks Star, but I still can't see the spectrogram behind it...
modified it...
%%%%%%%%%%%%%%%%
figure(3),clf
surf(phas_freqs,ampl_freqs,plv_modindex_comodulogram', 'EdgeColor','none')
hold on
contour3(phas_freqs,ampl_freqs,logical(z_modulation)', 'Color','m', 'LineWidth',2)
hold off
view(0, 90)
I would need your data to definitively determine what the problem is.
However, if you know what the level of the contour is that you want, select only that contour. I suspect that it is plotting the base contour and one other contour. That may be the result of the logical call. If you only want to see the contour values that are equal to 1 (or whatever value, since I have no idea what the matrix contains), something like this:
contour3(phas_freqs,ampl_freqs,z_modulation', [1 1], 'Color','m', 'LineWidth',2)
may be appropriate. That selects one contour (equal to 1 in this instance) and only plots that contour level.
Thanks so much again Star. I've attached the matrices to this reply and code below...
phas_freqs = 1:1:20;
ampl_freqs = 1:2:70;
% modindex_comodulogram = 20x35 double matrix of numbers
% z_modulation = 20x35 double matrix of Z-VALUES OF THE modindex_comodulogram
figure(8), clf
contourf(phas_freqs,ampl_freqs,modindex_comodulogram',40,'linecolor','none');
hold on
contour(phas_freqs,ampl_freqs,logical(z_modulation)',1,'linecolor','m','LineWidth',3);
xlabel('Frequency for phase')
ylabel('Frequency for amplitude')
title(['PAC in ' EEG.setname ': ' EEG.chanlocs(chani).labels])
colorbar
a=colorbar;
ylabel(a,'Modulation Index','FontSize',10);
I plotted the surf plot of ‘z_modulation’ so I could understand what it looked like. Once I understood that, the rest went smoothly. It nevertheless required a bit of tweaking to get this working correctly.
Here you go —
LD = load(websave('JH_onePlotBothMatrices','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136090/JH_onePlotBothMatrices.mat'));
modindex_comodulogram = LD.plv_modindex_comodulogram;
z_modulation = LD.z_modulation;
phas_freqs = 1:1:20;
ampl_freqs = 1:2:70;
% modindex_comodulogram = 20x35 double matrix of numbers
% z_modulation = 20x35 double matrix of Z-VALUES OF THE modindex_comodulogram
figure(8), clf
contourf(phas_freqs,ampl_freqs,modindex_comodulogram',100,'linecolor','none');
colormap(turbo) % <— OPTIONAL
hold on
contour(phas_freqs,ampl_freqs,z_modulation'+0.5, [0 0],'linecolor','m','LineWidth',3);
view(0,90)
xlabel('Frequency for phase')
ylabel('Frequency for amplitude')
% title("PAC in " + string(EEG.setname) ": " string(EEG.chanlocs(chani).labels)) % Using 'string' Arrays
colorbar
a=colorbar;
ylabel(a,'Modulation Index','FontSize',10);
The title call threw an error (no arguments), so I commented it out for the time being.
.
Star, your code works beautifully and I am very happy! Thank you so much!!!
Can also get there with the original code by saving the clim after the first plot and setting to that vlaue after the second.
LD = load(websave('JH_onePlotBothMatrices','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136090/JH_onePlotBothMatrices.mat'));
modindex_comodulogram = LD.plv_modindex_comodulogram;
z_modulation = LD.z_modulation;
phas_freqs = 1:1:20;
ampl_freqs = 1:2:70;
% modindex_comodulogram = 20x35 double matrix of numbers
% z_modulation = 20x35 double matrix of Z-VALUES OF THE modindex_comodulogram
figure(8), clf
contourf(phas_freqs,ampl_freqs,modindex_comodulogram',100,'linecolor','none');
colormap(turbo) % <— OPTIONAL
clim = get(gca,'CLim');
hold on
%contour(phas_freqs,ampl_freqs,z_modulation'+0.5, [0 0],'linecolor','m','LineWidth',3);
contour(phas_freqs,ampl_freqs,logical(z_modulation)',1,'linecolor','m','LineWidth',3);
set(gca,'CLim',clim)
view(0,90)
xlabel('Frequency for phase')
ylabel('Frequency for amplitude')
% title("PAC in " + string(EEG.setname) ": " string(EEG.chanlocs(chani).labels)) % Using 'string' Arrays
colorbar
a=colorbar;
ylabel(a,'Modulation Index','FontSize',10);

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!