Creating a graph with error bars

조회 수: 7 (최근 30일)
Ran Kagan
Ran Kagan 2022년 6월 25일
댓글: Dyuman Joshi 2022년 6월 25일
Hi,
For this given data arrays:
three_o=[0.933, 0.92];
error_three_o=[0.0019,0.0021];
three_r=[0.926,0.909];
error_three_r=[0.0017,0.0018];
four_o=[0.876,0.934];
error_four_o=[0.0017, 0.0012];
four_r=[0.875,0.903];
error_four_r=[0.0016,0.0015];
I've been trying to use errorbar function to create a readable error whiskers, like so:
This is the code I wrote, which kinda did the trick, although I hav some issues with the errorbars...:
scatter(3, [three_o],'red','*')
hold on
scatter(3, [three_r],'blue','+')
scatter(4, [four_o],'red','*')
scatter(4, [four_r],'blue','+')
legend({'Oven','', 'Regular'})
errorbar([3 3], [three_o],error_three_o)
errorbar([3 3], [three_r],error_three_r)
I'm getting very mixed-up error bars, with weird colors (I want them to be simply black), weird proportions (the errors themselves are really low and yet the vertical lines seem very long, representing a large error and overlapping with one another. The errors are also somehow added to the legend of the graph which I do not want to (I wrote the legend function before the errorbar function so I expected the errors not to be included).
Any thoughts?
Thanks!

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2022년 6월 25일
편집: Bjorn Gustavsson 2022년 6월 25일
You can use the errorbar function for plots like this. Check the help and documentation for that function. If that function doesn't entirely satisfy you there are a couple of alternatives on the file exchange. For example: al_goodplot-boxblot-violin-plot, alternative-box-plot, boxplot2 and notboxplot.
HTH
  댓글 수: 3
Bjorn Gustavsson
Bjorn Gustavsson 2022년 6월 25일
The errorbar function by default connect the central points with solid lines. In your plot you get that line vertical since you have the same x-coordinate for both. Try this:
ph1 = scatter(3, [three_o],'red','*');
hold on
ph2 = scatter(3, [three_r],'blue','+');
ph3 = scatter(4, [four_o],'red','*');
ph4 = scatter(4, [four_r],'blue','+');
errorbar([3 3], [three_o],error_three_o,'.')
errorbar([3 3], [three_r],error_three_r,'.')
legend([ph1(1),ph2(1)],{'Oven','', 'Regular'})
"Always" make a habit of taking the plot-handles out from the plotting-calls that you want to include in the legend - that way you have explicit control over what goes into the legend.
Dyuman Joshi
Dyuman Joshi 2022년 6월 25일
I was not aware of errorbar. TIL, Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by