connecting each data points in a bar graph with an error bar
12 次查看(过去 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!