Filter löschen
Filter löschen

Log-log plot with error band that has negative numbers

7 Ansichten (letzte 30 Tage)
L'O.G. am 16 Jan. 2023
Kommentiert: dpb am 17 Jan. 2023
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.

Akzeptierte Antwort

dpb am 16 Jan. 2023
Verschoben: dpb am 16 Jan. 2023
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 Kommentar
dpb am 17 Jan. 2023
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)




Community Treasure Hunt

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

Start Hunting!

Translated by