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

25 次查看(过去 30 天)
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,8:44
% 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

更多回答(0 个)

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by