Creating a graph with error bars
3 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
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
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.
参考
カテゴリ
Help Center および File Exchange で Errorbars についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!