How do i prevent boxplots from overlapping in a for loop?

8 vues (au cours des 30 derniers jours)
Frederike Vincent
Frederike Vincent le 2 Nov 2019
Dear all,
I am using a for-loop to plot different boxplots of a certain group but with slightly different values. WHen running the loop, the different boxes are plotted on top of each other in stead of next to each other. I would like to have a plot with for each class (8 classes) the five different boxplots calculated by the for loop next to each other, so in total 40 boxplots grouped per 5 next to each other.
Does anyone have an idea on how to do this?
%% Plot Tb in function of salinity for multiple vegetation classes
% Horizontal Polarization
fig_box_Tbh_veg = figure;
index=1;
Mh=zeros(length(s_list),length(lai_list)*length(veg_cls_list));
for veg_cls = veg_cls_list
param=extract_lookup_RTMparam(option,veg_cls,soil_cls,inc);
for lai=lai_list
data={};
for s = s_list
[Tbh,Tbv,c_er] = RTM_forward(opt, rtmv, T5, lai, Tc, tair, param,s,t);
data{end+1,1}= veg_cls;
data{end,2}=s;
data{end,3}=Tbh;
data{end,4}=Tbv;
data{end,5}=c_er;
end
table=cell2table(data,'VariableNames',{'Vegetation_class','Salinity','Tb_horizontal','Tb_vertical','dielectric_constant'});
disp(table);
Mh(:,index)=table.Tb_horizontal;
index=index+1;
end
end
boxplot(Mh);
xlabel('Vegetation type');
ylabel('Tb Horizontal polarization');
hold off

Réponse acceptée

Cris LaPierre
Cris LaPierre le 2 Nov 2019
Boxplot allows you to also specify a grouping variable. I'd put all the data into a single table, and then use the following code to create boxplots of Tb Horizontal polarization grouped by Vegetation type:
boxplot(table.Tb_horizontal,table.Vegetation_class);
Can you include an image of what you are seeing? Or the data necessary to run your code? It's much easier to help if we can play around with the example.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by