Creating a graph with error bars

2 views (last 30 days)
Ran Kagan
Ran Kagan on 25 Jun 2022
Commented: Dyuman Joshi on 25 Jun 2022
For this given data arrays:
three_o=[0.933, 0.92];
error_four_o=[0.0017, 0.0012];
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?

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 25 Jun 2022
Edited: Bjorn Gustavsson on 25 Jun 2022
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.
Dyuman Joshi
Dyuman Joshi on 25 Jun 2022
I was not aware of errorbar. TIL, Thanks!

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by