connecting each data points in a bar graph with an error bar
13 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Star Strider
2024 年 3 月 15 日
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 件のコメント
その他の回答 (1 件)
Chunru
2024 年 3 月 15 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Oceanography and Hydrology についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!