Limit a CONTOURF plot under a line

9 ビュー (過去 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 Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by