Error bars and legend order inconsistent?
Afficher commentaires plus anciens
Hi Matlab community,
I'm trying to create a line plot with error bars where the colour of the error bars and the colour of the lines vary based on a the value of the class (in this case a subsampling factor). However, I'm having two errors:
- In the legend, the order of the 'patches' do not correspond to the order of the 'labels' - I have no option to do this manually so cannot define the label order manually. The lowest numbers are meant to correspond to the darkest colours.
- Some of the patches in the legend show without error bars, whereas others do, despite the fact that errorbars are defined and plotted for each line.
I can't upload sample data unfortunately as the dataset is too large. I've included a sample of my code below as well as a screenshot showing the issue:

for j = 6:10
Norm_Opt{j}= Optimal_Results{j}./Optimal_Results{11}; %Normalise optimal results
Norm_Per25{j}=Per_25_Results{j}./Per_25_Results{11}; %Normalise 2.5% and 97.5% confidence intervals (improves visualisation)
Norm_Per975{j}=Per_975_Results{j}./Per_975_Results{11};
cmapUS = copper(US_FactorM); %Define colormap length based on maximum value
if Output{j}.geo.US >0
nUS = nUS +1
US_Factor(nUS) = Output{j}.geo.US_Factor; %Extract subsampling factor (for FaceColor)
subplot(3,1,1)
plot(x,Norm_Opt{j},'Color',cmapUS(((US_Factor(nUS)/US_FactorM)*length(cmapUS)),:),'LineWidth',3)
eUS(nUS)=errorbar(Norm_Opt{j},Norm_Per975{j});
eUS(nUS).Color = cmapUS(((US_Factor(nUS)/US_FactorM)*length(cmapUS)),:);
eUS(nUS).LineWidth = 2;
axis tight
daspect([0.1 1 1])
lgdUS{nUS}=num2str(US_Factor(nUS)); %Format legend labels
l = legend(lgdUS)
l.FontSize = 14;
hold on
end
end
Any help would be much appreciated, thanks a lot!
Ben
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!