Plot vertical curves on top of a 2D heat map
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have two vectors, x,y, and I am plotting a matrix Z of dimensions lenght(x)*lenght(y) by:
imagesc([min(x) max(x)], [min(y) max(y)], Z); caxis([-contrast_max contrast_max]); axis xy;axis tight;
pbaspect([1 1 1]); colorbar;
So far all good.
Now, in the resulting 2D heat map, I want to plot several curves that will appear on top of the heat map.
Let's say these curves are in an array C whose number of rows is precisely lenght(y) (C is some function of the magnitude y). I was trying to do:
for i = 1:size(C,2)
plot( C(:,i), y, '-');
end
But this does nothing. I attach a figure made by hand to illustrate the desired outcome:
In summary, how to do these two things (plotting a 2D heat map and curves) on the same plot?
1 Kommentar
dpb
vor etwa 15 Stunden
for i = 1:size(C,2)
plot( C(:,i), y, '-');
end
Besides not seeing a "hold on" in which case plot() will have replaced the image; the above is using the ith column of the array C as the x value and the y vector defined above as the y value--is that really what was intended? That would be the number of columns number of lines at a set of x values; all with the same y. Actually, that may be what is intended; if so, then simply adding hold on first will do the trick, although since MATLAB plots columns by default, you don't even need the loop.
plot(C,y,'r--','linewidth',2)
Antworten (1)
dpb
vor etwa 17 Stunden
Bearbeitet: dpb
vor etwa 17 Stunden
L=40*membrane(1,25);
imagesc(L)
xline(fix(width(L)/2),'r-','linewidth',2)
Seems to work to put a vertical line on top of an image; where you may have gone wrong is not using "hold on" with plot() instead of xline which inately does since its purpose is precisely for that effect.
Oh---on rereading the Q? it appears you want a curve that isn't just perfectly vertical in which case will need to draw. it..
figure
imagesc(L)
hold on
x=1:width(L);
y=x.^3; y=50*y/max(y);
line(x,y,'linestyle','-','color','r','linewidth',2)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!