Plot vertical curves on top of a 2D heat map

4 ビュー (過去 30 日間)
diego solerpolo
diego solerpolo 2024 年 12 月 3 日
コメント済み: diego solerpolo 2024 年 12 月 6 日
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 件のコメント
dpb
dpb 2024 年 12 月 3 日
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)

サインインしてコメントする。

採用された回答

dpb
dpb 2024 年 12 月 3 日
編集済み: dpb 2024 年 12 月 3 日
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)
  1 件のコメント
diego solerpolo
diego solerpolo 2024 年 12 月 6 日
Thank you so much! thak works fine :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by