Creating three shaded regions in a loglog plot
10 次查看(过去 30 天)
显示 更早的评论
I'm trying to create three regions with different colors on a loglog plot. I've tried implementing the patch function but every iteration that I've tried to imlement just screws the entire figure. I've verified that there are no negative values so not sure what is going on. Any help would be much appreciated!
R = 8.31;
N = 6.022e23;
Dia_air = 3.5e-10;
P = 101325;
Kn_1 = 0.1;
Kn_2 = 10;
Dia_al = [1e-2,1e-1,1e0,1e1,1e2]*1e-6;
T_1= flip(Kn_1*(sqrt(2)*pi()*Dia_air^2*N*P.*Dia_al)/R);
T_2= flip(Kn_2*(sqrt(2)*pi()*Dia_air^2*N*P.*Dia_al)/R);
figure(1)
loglog(Dia_al/1e-6,T_1,'k--')
hold on
loglog(Dia_al/1e-6,T_2,'k')
xlim([1e-2 1e2])
ylim([1e1 1e5])
hold off
0 个评论
采纳的回答
Star Strider
2024-3-28
编辑:Star Strider
2024-3-28
Perhaps something like this —
R = 8.31;
N = 6.022e23;
Dia_air = 3.5e-10;
P = 101325;
Kn_1 = 0.1;
Kn_2 = 10;
Dia_al = [1e-2,1e-1,1e0,1e1,1e2]*1e-6;
T_1= flip(Kn_1*(sqrt(2)*pi()*Dia_air^2*N*P.*Dia_al)/R);
T_2= flip(Kn_2*(sqrt(2)*pi()*Dia_air^2*N*P.*Dia_al)/R);
figure(1)
loglog(Dia_al/1e-6,T_1,'k--')
hold on
loglog(Dia_al/1e-6,T_2,'k')
patch([Dia_al flip(Dia_al)]/1e-6, [ones(size(T_1))*min(T_1) flip(T_1)], 'r', 'EdgeColor','none')
patch([Dia_al flip(Dia_al)]/1e-6, [T_1 flip(T_2)], 'b', 'EdgeColor','none')
patch([Dia_al flip(Dia_al)]/1e-6, [T_2 ones(size(T_2))*max(ylim)], 'g', 'EdgeColor','none')
xlim([1e-2 1e2])
ylim([1e1 1e5])
hold off
The patch calls require a closed contour, and that can be provided by choosing the y-vectors apporopriately, since they all share the same x-vector.
EDIT — Added: 'EdgeColor','none' to each patch call.
Note that in earlier versions of MATLAB (I do not remember when that changed), patch does not work with logarithmic axis scales. In that event, use plot for the loglog calls, keep the patch calls as they are, and afterwards use:
set(gca, 'XScale','log', 'YScale','log')
.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!