Limit a CONTOURF plot under a line
5 views (last 30 days)
Show older comments
Hi,
I want to limit the contour plot of u under the black curve h wich is a function of x: h=h(x). Indeed, u is a function of x and h: u=u(x,h). How may I do it? Thanks in advance for your help. Until now, I wrote the following code:
yyaxis left
plot(x,B)
xlabel("dimensional streamwise")
ylabel("magnetic field")
yyaxis right
plot(x,h)
ylabel("dimensional interface")
grid on
hold on
[X,Y]= meshgrid(x,h);
U=ones(1000).*u;
contourf(X,Y,U,'edgecolor','none')
hold on
colorbar
% dimensions of the variables
% x 1000x1
% B 1000x1
% h 1000x1
% u 1000x1
% U 1000x1000
Regards,
Andrea

0 Comments
Answers (1)
DGM
on 11 Aug 2021
Consider:
numpoints = [1000 1000]; % [x y]
% build boundary curve
x = linspace(-2,2,numpoints(1));
y = 4*x-x.^3;
% build 2D map
y2 = linspace(-4,4,numpoints(2)).';
z = sin(x*2).*sin(y2*2);
% set unwanted map data to NaN
z(y2>y) = NaN;
% pcolor is probably what you're after
pcolor(x,y2,z)
% or you could use contourf if that's really what you want
%contourf(x,y2,z,'edgecolor','none')
hold on
% using a thick line helps hide the ragged edge
h = plot(x,y,'k','linewidth',3);
colormap(summer)
shading flat
0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!