How can I plot 2D streamlines on top of a surf plot?

3 ビュー (過去 30 日間)
Arthur
Arthur 2024 年 10 月 25 日
コメント済み: Arthur 2024 年 10 月 25 日
I have a 3D surf plot of the variable 'conc' - a matrix of size (Nx x Ny) which I am plotting as surf(x, y, conc') and then using view(2) to view in 2D top down. I also have matrices uX and uY also of size (Nx x Ny). I make 2D streamlines/streamslices of these in the standard manner and then wish to plot these as an overlay on the surf figure, so that the streamlines appear on top of any surf.
The issue is that the surf figure has z values associated with conc whereas the streamlines are entirely 2D so always render underneath. Does anyone know how I may fix this?
Code is below. I use streamslice here but I have also tried with streamlines (note that streamslice is preferred since I want directional arrows).
% conc plot first
figure(1);
surf(x,y,conc');
daspect([1 1 1]);
shading interp;
xlabel("$X$");
ylabel("$Y$");
view(2);
c = colorbar;
clim([1.0 1.2]);
% now streamlines
[X, Y] = meshgrid(x, y);
hold on
h=streamslice(X, Y, uX', uY');

採用された回答

KSSV
KSSV 2024 年 10 月 25 日
% conc plot first
[X,Y,Z] = peaks(100) ;
[uX,uY] = gradient(Z) ;
figure(1);
surf(X,Y,Z);
daspect([1 1 1]);
shading interp;
xlabel("$X$");
ylabel("$Y$");
view(2);
c = colorbar;
% clim([1.0 1.2]);
% now streamlines
hold on
h=streamslice(X, Y,uX, uY);
set(h,'Color','k');
for i=1:length(h)
zi = interp2(X,Y,Z,h(i).XData, h(i).YData);
h(i).ZData = zi;
end
  1 件のコメント
Arthur
Arthur 2024 年 10 月 25 日
This works - thanks so much!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by