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!