I have a Matlab code as follows, where I wish to plot contour lines over a pcolor field, and then fill these contour lines with a select color.
My code is as follows:
pcolor(u)
set(gca, 'layer', 'top')
colormap(gca,colormap2)
hold on
contourf(chi, [threshold threshold], 'r', 'linewidth', linewidth_thickness)
So, I can successfully plot the contour lines above the pcolor on this plot, but I cannot select the color inside the contour. Let's say I want to fill the contours will yellow, what do I do?
Related
I want two contour plot to show a threshold and I'm using
contourf(X,Y,Z,[-1,-1],'k');
contourf(X,Y,Z,[2,2],'w');
while X and Y a simple meshgrid.
I see that the matrix Z has values above -1 and above 1, so I'm expecting the two lines at -1 and 1 but I see only the first contour lines. What am I doing wrong? Do I get it wrong this property?
Edit: here an example
x = 0:5:180;
y = 0:5:355;
[X,Y] = meshgrid(x,y);
Z = 5*cos(X);
figure(1);## Heading ##
surf(X',Y',Z','EdgeColor','none');
view(2); colorbar;colormap(jet); hold on
contour(X',Y',Z',[-1,-1],'k','LineWidth',1);
contour(X',Y',Z',[2,2],'k','LineWidth',2);
legend('','1','2','Location','northeastoutside');
I saw that if I put the two contour in a new figure, the two are plotted. But when I use surf, I just see the [-1,-1] option.
Many thanks
edit2: using pcolor instead of surf (removing ,'EdgeColor','none') gives me the correct plot...Why? What changes?
What happens is that contourf is not a 3D ploting function, its a 2D plotting function. So when you ask to plot contour lines, it will always plot them at z=0. So your surf plot is "on top of" the contourf for z>0, as you are setting view(2).
Look at the example you gave, with a different view:
You can see both lines here.
pcolor plots a 2D image, not a 3D surface, so it works with pcolor or imagesc.
I have a plot with a few lines in Matlab and I want to control the line colors post-hoc:
figure; hold on;
for ind=1:4
plot(rand(1,10))
end
I know I can use
set(0,'DefaultAxesColorOrder',summer(4))
before plotting, to change the plot line colors, but (how) can I achieve the same thing after looking at the plot? Possibly try-out a few different colorschemata?
Each plot by default takes its color from the property 'ColorOrder' of their axis, which in turn is taken by default from the 'DefaultAxesColorOrder' of the groot object.
Once the plots have been created, you need to modify their colors individually; changing the above mentioned properties will not affect them:
g = findobj(gca, 'Type', 'line'); % children of current axis that are lines
c = summer(numel(g)); % desired color scheme, with that many colors
for k = 1:numel(g)
set(g(k), 'color', c(k,:));
end
I want to plot a series of lines, with each line being colored according to a certain weight. I stumbled accross this, but the problem is, I am plotting multiple things on one graph, where only one of the plot statements should be color weighted.
I'm using hold on; hold off;, but I only see the last graph. Thus, the final result is, I only see the color weighted plot statements, but not the other plot statements that should be plotted due to hold on; hold off;.
Here is my code, where upper*p is an n x 1 vector representing the intensity of each of the n lines:
cmap = colormap;
con_min = min(upper*p)*25;
con_max = max(upper*p)*25;
ind_upper = ceil((size(cmap,1)-1)*((con_min:con_max)'-con_min+1)/(con_max-con_min));
subplot(2,3,2);
hold on;
title('Gains');
set(gca,'ColorOrder',cmap(ind_upper,:),'NextPlot','replacechildren');
plot(flat','c');
plot(lower','c');
plot(upper');
set(gca, 'xtick',1:labelFreq:num_tickers, 'xticklabel', tickers(1:4:num_tickers));
ylabel('bp change on day');
colorbar;
caxis([con_min con_max]);
hold off;
It seems the "upper" part is plotted correctly according to the color weights, but the "flat" and "lower" graphs do not show. I think it's because the set(gca,...) statement is causing the graphs to reset.
I have the following code and I have plotted a 3D plot for the stft with respect to time, frequency and amplitude. How do I change the black color seen in the plot to white? I do not understand how to change the black color to white in colormap option
[ss,ff,tt,pp]= spectrogram(x_dc,128*2,60,128*2,Fs);
figure,surf(tt,ff,abs(ss))
Spectrogram
figure,surf(tt,ff,abs(ss), 'EdgeColor', 'none')
That 'black colour' you see are probably the borders of each cell. Don't show them using the 'EdgeColor', 'none' name-value pair.
I'm trying to make my surf plot transparent. This is my input:
surf(A,B,C,...
'EdgeColor', 'none',...
'FaceColor','interp')
colormap jet
alpha(.1);
I do not understand why code above isn't working.