Log-log plot with error band that has negative numbers

조회 수: 9 (최근 30일)
L'O.G. . 2023년 1월 16일
댓글: dpb . 2023년 1월 17일
How do I make an error band? I am attaching some sample data. The fill function generates negative numbers, so that when I try either this:
fill([x; flipud(x)],[y-std_y;flipud(y+std_y)],'k','FaceAlpha',0.5);
or this:
fill([x; flipud(x)],[y-std_y;flipud(y+std_y)],'k','FaceAlpha',0.5);
set(gca, 'XScale','log', 'YScale','log')
The error band doesn't show up.

채택된 답변

dpb 2023년 1월 16일
이동: dpb 님. 2023년 1월 16일
You simply can't plot negative numbers on a log axis...they don't exist (well, they do, but they're complex).
It's not the fill function's fault; it's that abs(std_y)>abs(y) for at least some of your y values. You'll get the same result if you just plot() y-std_y.
That's why I constrained the error magnitude in the previous example as was noted in the comments of the sample code.
  댓글 수: 1
dpb 2023년 1월 17일
You could illustrate the general effect if you were to choose a lower bound decade at which to cut off the lower limit and then clip the y_lo values at that point. Remember, however, that log(0) --> -Inf so there are an infinite number of decades to desplay to cover the full range even to get to the crossing point so the best you can hope for is a very crude representation.
In that regards, drawing the boundary line could be a better alternative; while it will also not show past where the data go to zero, it will display the points that are positive which is something. fill() is a one object for the defined region; the only way to draw it would be to only define regions for which the result is positive for the lower bound area and draw multiple areas -- the positive error above the data could be one, then depending upon the shape of the data, one or more to cover the areas on the lower side that are all greater than zero. This will leave one with a truncated area on the bottom as compared to the top, of course, but not really anything can do about that other than the aforementioned truncation of values to keep all positive -- but that misrepresents the values so don't really recommend it. The best solution probably is to just forego the log axis for linear if the data really do go negative.

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

추가 답변 (0개)




Community Treasure Hunt

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

Start Hunting!

Translated by