Vertical error bars disappear on logy plot

13 views (last 30 days)
I made a scatter plot then added error bars:
err = errorbar(statsx, avgs, error, 'LineWidth', 2, 'CapSize', 12);
err.LineStyle = 'none';
err.Color = 'b';
I then set the y axis to log:
set(gca, 'YScale', 'log')
... and about half of the negative error bars disappear. The bars which disappear are consistent whenever I re-run the script. When I set the axis back to linear, all bars re-appear.
What could be happening?

Accepted Answer

Walter Roberson
Walter Roberson on 9 Mar 2021
When you use Yscale log, then:
  • if all of the y coordinates are negative, a warning is given and plotting proceeds as if the values were positive; otherwise
  • no line is drawn to any vertex that has a negative y coordinate
  • no face is drawn for any surface or patch area that has a negative y coordinate
bar() plots are patch() objects, so if a bar has any negative y coordinates, that bar will not be drawn, not even if you ylim a positive lower bound. MATLAB will not attempt to find the intersection of the face and the ylim / xlim and draw only that part: the entire face will be omitted, same as if it had a coordinate that was infinite or nan.
Error bars themselves might have the limits drawn as line objects, so you can end up with the situation where an reference line is drawn (because its ends are positive) for a face that is not drawn (because it has a negative y coordinate somewhere)

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!