Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.4K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

Drawing ErrorBarLogPlots in Mathematica v10?

Hello, Mathematica Community :). I have Mathematica v10 installed in my computer. Does anybody know how to draw "errorbarloglogplot" in Mathematica v10? Thanks, Raju

POSTED BY: Raju Timsina

Please see other solutions HERE. Mine was the following:


A one-liner solution (see a bit below lengthy explanation)

This is a bit hacky solution, yet its simplicity prompted me to post it. Load package and make up a data set:

Needs["ErrorBarPlots`"]
data = Sort@RandomReal[1, {10, 2}]; error = RandomReal[0.2, 10];

errorplot = ErrorListPlot[Partition[Riffle[data, ErrorBar /@ error], 2], 
            Joined -> True, PlotRange -> All, Frame -> True, Axes -> False]

enter image description here

IMPORTANT: nothing goes below x-axis - not the data, not the error bars. Otherwise your log-scale will break - you cannot take log of negative numbers.

Now lets take a look at the "guts" of the produced graphics:

errorplot // InputForm

enter image description here

Line graphics primitive (sometimes with Offset) applied to sets of points given by coordinates like {x, y}. You just need to replace all these pairs by {x, Log@y}. Careful with Offset - its 1st argument needs to be left a lone. Luckily for us it has an integer 0 so it is easy to avoid applying a pattern that distinguishes it from real numbers we need to deal with.

So here is your one-liner solution:

lerrorplot = errorplot /. {x_Real, y_Real} -> {x, Log@y}

enter image description here

Notice undesirable non-standard ticks on vertical axes (corresponding to log values). To check that it is indeed correct - compare versus ListLogPlot:

check = ListLogPlot[data, Joined -> True, Frame -> True, 
Axes -> False, PlotStyle -> {Thickness[.03], Orange, Opacity[.3]}];
Show[check, lerrorplot, PlotRange -> All]

enter image description here

A perfect match. Notice the ticks on vertical axes now are in traditional log-scale type (corresponding to original un-scaled data). Of course, your error bars got log-scaled too. Warning: be careful with these ReplaceAll type of solutions - you may be up to a surprise to what exactly is getting replaced. So always analyse your code to avoid unpleasant urprises.

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard