Plotting Multiple Shaded Uncertainties
显示 更早的评论
Hi, I am relatively new to coding and having an issue plotting my data. I get files with element concentrations and uncertainties and I'd like to plot many of them on one figure with their corresponding figures shaded. I've gotten this code to work for shading the uncertainty for a single element, but I'm not sure this is accurate and the legend is offset (counting the shading as entries). Ideally I won't need a string of code for each element (I have 11 in my code currently but we measure 140). Thanks for any input!
X = Xactdata.Date(Data); % dates & times from instrument
Elements = [Xactdata.SULPHUR(Data),Xactdata.CHLORINE(Data),Xactdata.POTASSIUM(Data),Xactdata.CALCIUM(Data),Xactdata.TITANIUM(Data),Xactdata.IRON(Data),Xactdata.COPPER(Data),Xactdata.ZINC(Data),Xactdata.ARSENIC(Data),Xactdata.BROMINE(Data),Xactdata.BARIUM(Data)]; %element concentration
E_err = [Xactdata.S_U(Data),Xactdata.Cl_U(Data),Xactdata.K_U(Data),Xactdata.Ca_U(Data),Xactdata.Ti_U(Data),Xactdata.Fe_U(Data),Xactdata.Cu_U(Data),Xactdata.Zn_U(Data),Xactdata.As_U(Data),Xactdata.Br_U(Data),Xactdata.Ba_U(Data)]; %element uncertainty
E_Labels = {"S","Cl","K","Ca","Ti","Fe","Cu","Zn","As","Br","Ba"};
figure
for i = 1:11 %number of elements plotted
plot(X, Elements(:,i))
hold on
patch([x; flip(x)], [Elements(:,i)-E_err(:,i); flip(Elements(:,i)+E_err(:,i))], 'b', 'FaceAlpha',0.25, 'EdgeColor','none')
end
legend(E_Labels)
title('Element Concentrations')
ylabel('Concentration (ng/m^3)')
xlabel('Date (UTC)')
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 2-D and 3-D Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
