Error in bar graph legend with bar graph with two groups
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Krispy Scripts
le 26 Déc 2016
Réponse apportée : the cyclist
le 26 Déc 2016
I am trying to make a bar graph with two different groups. I have done almost everything, but I am trying to add a legend for group, but can only successfully get one legend to be labeled. My data is two columns.
Here is my code:
y=datain;
d1mean=mean(datain(:,1));
d2mean=mean(datain(:,2));
d1std= std( datain(:,1) ) / sqrt( length( datain(:,1) ));
d2std= std( datain(:,2) ) / sqrt( length( datain(:,2) ));
figure
hold
hb =bar(d1mean,'BarWidth',.75);
pause(0.1);
set(hb(1), 'FaceColor','b')
errorbar(d1mean,d1std,'k.');
xdata2=2;
hb =bar(d2mean,'BarWidth',.75,'Xdata',xdata2);
pause(0.1);
errorbar(xdata2,d2mean,d2std,'k.');
set(hb(1), 'FaceColor','r')
hold on
hbc = get(hb, 'Children');
legend(hbc,'Correct','Not Correct');
Here is my data for this figure:
datain = -0.000271345000000000 -0.000267704000000000
-0.000301474000000000 -0.000344932000000000
-1.52000000000000e-05 -3.51000000000000e-05
-2.36000000000000e-05 -3.41000000000000e-05
-3.67000000000000e-06 -0.000107296000000000
-0.000155831000000000 -0.000257319000000000
3.86000000000000e-05 -4.28000000000000e-05
4.48000000000000e-05 -0.000155381000000000
-9.51000000000000e-05 -0.00200064000000000
0.000132163000000000 -0.00133529700000000
-0.000193404000000000 9.84000000000000e-05
0.000191851000000000 -0.000174665000000000
9.88000000000000e-05 8.33000000000000e-05
0.00182427300000000 0.000713032000000000
-0.000626424000000000 0.00382225100000000
0.000407865000000000 0.000141848000000000
-0.000217450000000000 -0.000293288000000000
-4.02000000000000e-05 -0.000203370000000000
0.000843427000000000 -0.000152465000000000
0.00100842500000000 0.000150815000000000
-0.000390770000000000 0.000363063000000000
0.000187511000000000 -0.000190416000000000
4.42000000000000e-05 9.53000000000000e-06
-0.000350348000000000 0.000440978000000000
-4.52000000000000e-05 1.89000000000000e-05
-1.13000000000000e-05 7.46000000000000e-05
-0.00118165100000000 -2.48000000000000e-05
-0.000601596000000000 -0.000942368000000000
-0.000663966000000000 -0.000572282000000000
0.00332484100000000 0.000316277000000000
6.92000000000000e-05 -0.000125089000000000
-0.000190756000000000 -9.53000000000000e-05
-0.00175938700000000 -0.000407673000000000
0.00357178000000000 -0.000382842000000000
-0.0360602630000000 -0.0150118600000000
0.0170111500000000 0.00335633900000000
0.00188138800000000 -0.00180161300000000
-0.000870726000000000 -0.00221083000000000
-0.000154684000000000 0.00318132900000000
-0.00110678900000000 -0.00160783300000000
0.000142479000000000 -0.000337943000000000
-3.60000000000000e-05 -4.76000000000000e-05
-0.00649187900000000 -0.00548735400000000
-0.00340032800000000 0.0106501950000000
0.000808602000000000 0.00116598700000000
-0.000303465000000000 2.26000000000000e-05
-0.000118639000000000 -0.000186277000000000
-0.000243804000000000 0.000100178000000000
-0.00108102300000000 0.000255303000000000
-0.000737168000000000 -0.000227166000000000
-0.000272970000000000 -5.82000000000000e-05
-1.46000000000000e-05 -0.000279268000000000
-0.000105326000000000 -0.000150069000000000
-4.63000000000000e-05 -9.56000000000000e-06
-0.000184068000000000 0.000430325000000000
-0.000507061000000000 -0.00101489200000000
0.000216693000000000 0.000316612000000000
7.38000000000000e-05 0.000110001000000000
0.000182687000000000 -0.000774168000000000
0.00200378300000000 -0.000933046000000000
0.000218153000000000 0.000509206000000000
-7.62000000000000e-05 5.11000000000000e-05
-4.06000000000000e-05 -0.000555562000000000
8.81000000000000e-05 -0.000788831000000000
-0.000188799000000000 0.00146255700000000
0.000222302000000000 4.85000000000000e-05
-0.000124519000000000 -0.000159541000000000
-0.000151391000000000 -0.000198232000000000
-0.000809613000000000 -0.000139193000000000
-0.000227146000000000 0.000418432000000000
-0.000153166000000000 3.34000000000000e-05
-3.11000000000000e-05 0.000589589000000000
0.00456111100000000 -0.00411876500000000
-0.00191101400000000 -0.00261410300000000
6.28000000000000e-05 -0.000452229000000000
0.000285205000000000 -0.000449552000000000
2.60000000000000e-05 -5.48000000000000e-05
-7.52000000000000e-05 9.31000000000000e-05
0.000389031000000000 6.93000000000000e-05
-0.000428742000000000 -6.89000000000000e-05
0.00125381300000000 -0.000288931000000000
-0.000254823000000000 -0.000501194000000000
-0.000108110000000000 -0.000217084000000000
-0.000178516000000000 0.000500603000000000
-0.000109677000000000 0.000173589000000000
-0.000128441000000000 -3.04000000000000e-05
Here is what my figure is coming out as:
How do I get the not correct to be red?
0 commentaires
Réponse acceptée
the cyclist
le 26 Déc 2016
y=datain;
d1mean=mean(datain(:,1));
d2mean=mean(datain(:,2));
d1std= std( datain(:,1) ) / sqrt( length( datain(:,1) ));
d2std= std( datain(:,2) ) / sqrt( length( datain(:,2) ));
figure
hold on
hb(1) =bar(d1mean,'BarWidth',.75);
pause(0.1);
set(hb(1), 'FaceColor','b')
errorbar(d1mean,d1std,'k.');
xdata2=2;
hb(2) =bar(d2mean,'BarWidth',.75,'Xdata',xdata2);
pause(0.1);
errorbar(xdata2,d2mean,d2std,'k.');
set(hb(2), 'FaceColor','r')
legend(hb,'Correct','Not Correct');
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!