Limit a CONTOURF plot under a line

조회 수: 5 (최근 30일)
Andrea Palmarini
Andrea Palmarini 2021년 8월 10일
답변: DGM 2021년 8월 11일
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

답변 (1개)

DGM
DGM 2021년 8월 11일
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

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by