Creating three shaded regions in a loglog plot
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 28 Mar 2024
Edited: Star Strider
on 28 Mar 2024
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')
.
2 Comments
More Answers (1)
See Also
Categories
Find more on Polygons 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!