How to color or patch the region between a curve and the x axis

4 次查看(过去 30 天)
My code plots two curves. I want to color or in other words patch the region between the curves and the x-axis from 3-5 um. I am not sure how to properly define the y patch so my patch doesn't fill up the correct region of interest. Any form of help would be appreciated. Thank you.
clc;
close all;
c=3*10^8; % speed of light in vaccum
h=6.626*10.^-34; % Planck constant
k=1.38*10.^-23; % Boltzmann constant
T=[700 900]; % Temperatures in Kelvin
Lam=(0.0:0.01:50)*1e-6; % in meters
figure(1)
for i=1:2
A2(:,i)=(2*pi*h*c*c)./((Lam.^5).*(exp((h.*c)./(k.*T(i).*Lam))-1));
hold on
plot(Lam*1e6,A2(:,i)*1e-10,'r','linewidth',2)
x = [3 5]; % Define x For patch
y = [0.152 0.19]; % Define y For patch
patch([x fliplr(x)], [zeros(size(y)) fliplr(y)], 'b')
hold off
xlabel('\lambda (\mum)','fontsize',20)
ylabel('Spectral exitance (W/cm^2/\mum)','fontsize',20) %for I2
title('Blackbody Radiation','fontsize',24)
ax=gca;
ax.XRuler.Exponent=0;
xlim([0 20])
end
  2 个评论
Emmanuel Sarpong
Emmanuel Sarpong 2023-8-25
Yes I do care. I am trying to also figure out how to integrate the shaded portion under each curve (after being able to do the shading or patching properly) so I am trying to stay within the region of interest. Thanks

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2023-8-25
I posted this in response to your Comment (I’ve since deleted my responding Comment), so I’m now posting it as an Answer here —
c=3*10^8; % speed of light in vaccum
h=6.626*10.^-34; % Planck constant
k=1.38*10.^-23; % Boltzmann constant
T=[700 900]; % Temperatures in Kelvin
Lam=(0.0:0.01:50).'*1e-6; % in meters
Lv = (Lam <= 5E-6) & (Lam >= 3E-6); % <— ADDED
cm = [0 0 1; 1 0 0]; % <— ADDED
figure(1)
for i=1:2
A2(:,i)=(2*pi*h*c*c)./((Lam.^5).*(exp((h.*c)./(k.*T(i).*Lam))-1));
hold on
plot(Lam*1e6,A2(:,i)*1e-10,'r','linewidth',2)
x = Lam*1e6; % Define x For patch % <— CHANGED
y(:,i) = A2(:,i)*1e-10; % Define y For patch % <— CHANGED
if i == 1
patch([x(Lv); flip(x(Lv))], [zeros(size(y(Lv,1))); flip(y(Lv,i))], cm(i,:), 'FaceAlpha',0.5, 'EdgeColor','none') % <— CHANGED
elseif i == 2
patch([x(Lv); flip(x(Lv))], [y(Lv,1); flip(y(Lv,2))], cm(i,:), 'FaceAlpha',0.5, 'EdgeColor','none') % <— CHANGED
end
hold off
xlabel('\lambda (\mum)','fontsize',20)
ylabel('Spectral exitance (W/cm^2/\mum)','fontsize',20) %for I2
title('Blackbody Radiation','fontsize',24)
ax=gca;
ax.XRuler.Exponent=0;
xlim([0 20])
end
.
  5 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by