
Adding Color Under Certain Areas of Function Plot
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Chase Valo
am 13 Dez. 2019
Kommentiert: Star Strider
am 15 Dez. 2019
I need to add color to certain areas under the plotted function but can not get anything I try to work. Help would be much appreciated.
This is what I have so far:
%% Part 1: Solar Radiation
%Constants:
h = 6.626e-34;
k = 1.381e-23;
c = 2.998e8;
t = 5800;
r_sun = 1.39e9/2;
r_earth = 1.5e11;
f_w = (r_sun/r_earth)^2;
%Function:
L_sun =@(l) f_w*((2*pi*h*c^2)./l.^5).*(1./(exp(h*c./(l*k*t))-1));
%Plotting Function:
figure(1)
fplot (L_sun, [0,3e-6],'LineWidth',2)
x0=10;
y0=10;
width=675;
height=500;
title('Solar Spectral Irradiance','fontsize',14)
ylabel('Spectral irradiance(W*m^-^2)','fontsize',14)
xlabel('Wavelegth(m)','fontsize',14)
axes('pos',[.4 .6 .5 .3])
%imshow('equation(1).png')
%% Part 2: Energy Distrubution
%I added below ths line when using the bounds use the nanometers since
% we are in meters everthing needs to be conveted.
l = [0:0.01e-6:3e-6];
X = f_w*((2*pi*h*c^2)./l.^5).*(1./(exp(h*c./(l*k*t))-1));
Max = max(X) %maximum irradiance
%Energy recieved by region:
UV = integral(L_sun,0,0.38e-6)
Vis = integral(L_sun,0.38e-6,0.78e-6)
IR = integral(L_sun,0.78e-6,3e-6)
This is the plot I currently have:

Below is what I am trying to accomplish:

0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Dez. 2019
Try this:
% %% Part 1: Solar Radiation
%Constants:
h = 6.626e-34;
k = 1.381e-23;
c = 2.998e8;
t = 5800;
r_sun = 1.39e9/2;
r_earth = 1.5e11;
f_w = (r_sun/r_earth)^2;
%Function:
L_sun = @(l) f_w*((2*pi*h*c^2)./l.^5).*(1./(exp(h*c./(l*k*t))-1));
patchfun = @(x,c) patch([x fliplr(x)], [L_sun(x) zeros(size(x))], c);
%Plotting Function:
figure(1)
fplot (L_sun, [0,3e-6],'LineWidth',2)
hold on
region_1 = linspace(0.1,0.4,25)*1E-6;
patchfun(region_1,'r')
region_2 = linspace(0.4, 0.75, 25)*1E-6;
patchfun(region_2, 'g')
region_3 = linspace(0.75, 3, 25)*1E-6;
patchfun(region_3, 'b')
hold off
This is only the part of your code that is relevant to your Question. (The patch function requires a bit of practice to use.) Since the function call is the same for the various regions, I created the anonymous function ‘patchfun’, and then called it for each region.
Experiment to get the result you want.

2 Kommentare
Weitere Antworten (1)
Image Analyst
am 13 Dez. 2019
Try patch() or fill()
2 Kommentare
Image Analyst
am 15 Dez. 2019
Bearbeitet: Image Analyst
am 15 Dez. 2019
Of course. Star Strider is passing in numbers. What were you trying to pass in? A character string???
Siehe auch
Kategorien
Mehr zu Color and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!