connecting each data points in a bar graph with an error bar
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I would like to connect those two corresponding points from one bar graph to another (first dot to another first dot).
I have a code like this now to give a bar graph and an error and each individual data points. Could help how I can connect points? thanks.
Saline1 = [41 55];
Saline2 = [34 26];
bar(1,mean(Saline1), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
bar(2,mean(Saline2), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
plot(1,Saline1,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
plot(2,Saline2,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
errorbar(1,mean(Saline1),(std(Saline1)/sqrt(size(Saline1,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0])
hold on
errorbar(2,mean(Saline2),(std(Saline2)/sqrt(size(Saline2,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0])
hold on
0 Commenti
Risposta accettata
Star Strider
il 15 Mar 2024
Sure!
The easiest way is probably to return the handles of the errorbar calls to get the ‘XData’, ‘YData’, ‘’YPOsitiveDelta’, and ‘YNegativeDelta’ values, and use those to plot the lines.
Try this —
Saline1 = [41 55];
Saline2 = [34 26];
bar(1,mean(Saline1), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
bar(2,mean(Saline2), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
plot(1,Saline1,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
plot(2,Saline2,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
heb1 = errorbar(1,mean(Saline1),(std(Saline1)/sqrt(size(Saline1,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0]);
% get(heb1)
hold on
heb2 = errorbar(2,mean(Saline2),(std(Saline2)/sqrt(size(Saline2,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0]);
plot([heb1.XData heb2.XData], [heb1.YData+heb1.YPositiveDelta heb2.YData+heb2.YPositiveDelta], '-r', 'LineWidth',2)
plot([heb1.XData heb2.XData], [heb1.YData-heb1.YNegativeDelta heb2.YData-heb2.YNegativeDelta], '-g', 'LineWidth',2)
hold off
.
0 Commenti
Più risposte (1)
Chunru
il 15 Mar 2024
Saline1 = [41 55];
Saline2 = [34 26];
bar(1,mean(Saline1), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
bar(2,mean(Saline2), 0.6, 'FaceColor',[0.7 0.7 0.7])
hold on
plot(1,Saline1,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
plot(2,Saline2,'--o','MarkerSize',10,'MarkerFaceColor',...
[0.3 0.3 0.3],'MarkerEdgeColor','none','Color',[0.3 0.3 0.3],'LineWidth',2)
hold on
e(1) = errorbar(1,mean(Saline1),(std(Saline1)/sqrt(size(Saline1,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0])
hold on
e(2) = errorbar(2,mean(Saline2),(std(Saline2)/sqrt(size(Saline2,2))),...
'LineStyle','none','LineWidth',2,'Color',[0 0 0])
hold on
%% link the positive delta
% Get the coordinates
x = [e.XData];
y = [e.YData] + [e.YPositiveDelta];
plot(x, y, 'b-')
0 Commenti
Vedere anche
Categorie
Scopri di più su Oceanography and Hydrology in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!