Plotting multiple functions, while showing only parts of them
3 次查看(过去 30 天)
显示 更早的评论
So, I have this code that plots the blackbody spectrum for two temperatures (so, technically two functions). The problem is that I don't want to plot the entire functions. I want the blue graph to stop after it reaches its maximum (given by the vertical line) so the part right to the max, and the orange plot to show only parts after it reaches its max (only parts to its right), because I want to plot a third linear function to connect these two maximums, Is that possible?
% plot the blackbody curves - spectral radiance at the aperture of the
% blackbody (L(nu,T)=(c/4pi)*u(nu,T)) where u is the spectral
% distribution of radiant energy in the blackbody
freq = c./(1e-6.*[0.0001:0.0001:0.05 0.05:0.01:10000.0]); % (Hz)
A = (h.*freq)./(k.*Tstar); % (dimensionless)
B = (2.0.*h./c^2).*(freq).^3; % (W/m2/sr/Hz)
BBSpectralRad = B.*(1.0./(exp(A)-1)); % (W/m2/sr/Hz)
plot(freq,BBSpectralRad);
hold all;
plot([freqStar freqStar],[1e-15 max(BBSpectralRad)], ...
'--','color',[0.5 0.5 0.5]);
grid on
hold all;
% label the plot
xlim([1e11 1e17]);
ylim([1e-15 1e-4]);
set(gca, 'YScale', 'log');
set(gca, 'XScale', 'log');
text(2e11,1e-7, ...
'$\nu_{peak} = 5.879\times 10^{10} T$', 'fontsize',16,'Interpreter','latex');
xlabel('\bf\fontname{arial}\fontsize{14}Frequency (\nu) [Hz]');
ylabel('\bf\fontname{arial}\fontsize{14}Spectral Radiance [W m^{-2} sr^{-1} {Hz}^{-1}]');
title('\bf\fontname{arial}\fontsize{14}Blackbody Radiation','Fontsize',14);
hold on
Tstar = 18974; % (K)
freqStar = WeinLawCnst.*Tstar; % (Hz)
freq = c./(1e-6.*[0.0001:0.0001:0.05 0.05:0.01:10000.0]); % (Hz)
A = (h.*freq)./(k.*Tstar); % (dimensionless)
B = (2.0.*h./c^2).*(freq).^3; % (W/m2/sr/Hz)
BBSpectralRad = B.*(1.0./(exp(A)-1)); % (W/m2/sr/Hz)
plot(freq,BBSpectralRad);
hold all;
plot([freqStar freqStar],[1e-15 max(BBSpectralRad)], ...
'--','color',[0.5 0.5 0.5]);
grid on
hold all;
1 个评论
回答(1 个)
Mara
2020-6-27
Hello,
you can plot only to the maximal y-value by finding the index of it in your vector of y-values. When you plot x and y, you specify that you only want to plot to that point or from that point on to the end.
idx = find(y==max(y));
plot(x(1:idx), y(1:idx)) % or plot(x(idx:end), y(idx:end))
you can also retrieve and change the x and y data later from the properties of your axes:
p = plot(x,y)
idx = find(p.YData == max(p.YData));
set(p, 'XData' , p.XData(1:idx), 'YData', p.YData(1:idx))
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!