Vertical error bars disappear on logy plot

11 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2021-3-9
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by