Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

errorbar on semilog plot

1,054 views
Skip to first unread message

Elnaz

unread,
Sep 24, 2012, 6:51:09 PM9/24/12
to
Dear all,

Does anyone know how to plot "errorbar" function on a semilogy axis?
If I use errorbar and then make the y axis logarithmic it will mess up the error bars.
Any suggestions?

Thanks,
Elnaz

dpb

unread,
Sep 24, 2012, 8:59:57 PM9/24/12
to
In what way does it "mess up" the error bars? They'll simply change to
reflect the values. If you mean you want symmetric errors on log scale
then compute and pass the lower/upper limits when call errorbar()
instead of using a single error value

doc errorbar

--

Elnaz

unread,
Sep 24, 2012, 11:14:10 PM9/24/12
to
dpb <no...@non.net> wrote in message <k3qvlv$ahs$1...@speranza.aioe.org>...
I am using precalculated lower and upper bounds for errorbar. However, changing to log scale, error bars don't adapt to the new curve. They don't change to reflect the values. They separate from the curve and seem like some horizontal lines.

dpb

unread,
Sep 25, 2012, 12:09:08 AM9/25/12
to
On 9/24/2012 10:14 PM, Elnaz wrote:
...

> I am using precalculated lower and upper bounds for errorbar. However,
> changing to log scale, error bars don't adapt to the new curve. They
> don't change to reflect the values. They separate from the curve and
> seem like some horizontal lines.

Just did

x=1:10;
y=rand(size(x));
eu=1.05*y;el=0.95*y;
errorbar(x,y,el,eu)
set(gca,'ylimit','log')

and looks just as I would expect--the error bars are asymmetric but
reflect the values as calculated...

--

Elnaz

unread,
Sep 25, 2012, 12:32:08 AM9/25/12
to
> Just did
>
> x=1:10;
> y=rand(size(x));
> eu=1.05*y;el=0.95*y;
> errorbar(x,y,el,eu)
> set(gca,'ylimit','log')
>
> and looks just as I would expect--the error bars are asymmetric but
> reflect the values as calculated...
>
> --
Maybe, since your bounds directly depend on y values but mine do not, only two vectors calculated using Wilson score interval.

dpb

unread,
Sep 25, 2012, 8:57:07 AM9/25/12
to
On 9/24/2012 11:32 PM, Elnaz wrote:
>> Just did
...[elided code for brevity]...
>> and looks just as I would expect--the error bars are asymmetric but
>> reflect the values as calculated...
>>
> Maybe, since your bounds directly depend on y values but mine do not,
> only two vectors calculated using Wilson score interval.

Well, then I must conclude the result is not be a problem caused by
errorbar() but fundamental to the data itself.

Post an example code snippet that produces the plot and what you think
is wrong and what you think the result should be...

--

Elnaz

unread,
Sep 25, 2012, 10:58:08 PM9/25/12
to
> Post an example code snippet that produces the plot and what you think
> is wrong and what you think the result should be...
i=1;
for EbN0 = -2:0.5:10
...
m=1;
while(frame_nb<30)
...
fer = frame_err/frame_nb;
ber(i) = bit_err/(frame_nb*k);
pu(i) = (fer+1.96^2/(2*m));
pl(i) = (fer+1.96^2/(2*m));
m=m+1;
end
i=i+1;
end

errorbar(-2:0.5:10,ber,pl,pu);
set(gca,'yscale','log');

This messes up the error bars!
Elnaz

dpb

unread,
Sep 25, 2012, 11:53:04 PM9/25/12
to
On 9/25/2012 9:58 PM, Elnaz wrote:
>> Post an example code snippet that produces the plot and what you think
>> is wrong and what you think the result should be...
...

>
> errorbar(-2:0.5:10,ber,pl,pu);
> set(gca,'yscale','log');
>
> This messes up the error bars!

a) You gave no way to produce the data--provide a set of vectors of
numbers or a way to generate values.

b) "Messes up" isn't a definitive description of what you think is
wrong, specifically, and

c) What do you think the result should be?

--

Elnaz

unread,
Sep 26, 2012, 12:08:08 AM9/26/12
to
> > errorbar(-2:0.5:10,ber,pl,pu);
> > set(gca,'yscale','log');
> >
> > This messes up the error bars!
>
> a) You gave no way to produce the data--provide a set of vectors of
> numbers or a way to generate values.
>
> b) "Messes up" isn't a definitive description of what you think is
> wrong, specifically, and
>
> c) What do you think the result should be?

a) This should do it:
ber = berawgn(-2:10,'oqpsk','nondiff');
pl =[0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522 0.166645626439589];
pu =[1 1 1 1 1 1 1 1 1 1 1 1 0.478761210116602];

errorbar(-2:10,10*log10(ber),pl,pu);
set(gca,'yscale','log');

b&c) I expect to get a curve with error bars as this one:
errorbar(-2:10,10*log10(ber),pl,pu);

Elnaz

dpb

unread,
Sep 26, 2012, 2:22:25 AM9/26/12
to
On 9/25/2012 11:08 PM, Elnaz wrote:
...

>> a) You gave no way to produce the data--provide a set of vectors of
>> numbers or a way to generate values.
...

> a) This should do it:
> ber = berawgn(-2:10,'oqpsk','nondiff');

...

Well, not quite...

>> ber = berawgn(-2:10,'oqpsk','nondiff');
??? Undefined function or variable 'berawgn'.

--

Elnaz

unread,
Sep 26, 2012, 9:31:07 AM9/26/12
to
> Well, not quite...
>
> >> ber = berawgn(-2:10,'oqpsk','nondiff');
> ??? Undefined function or variable 'berawgn'.
>
> --

Ok, that's a communication toolbox func. How about this?
ber = [0.130644488522829 0.103759095953406 0.0786496035251426 0.0562819519765415 0.0375061283589260 0.0228784075610853 0.0125008180407376 0.00595386714777866 0.00238829078093281 0.000772674815378444 0.000190907774075993 3.36272284196176e-05 3.87210821552205e-06];
Elnaz

Steven_Lord

unread,
Sep 26, 2012, 9:40:26 AM9/26/12
to


"dpb" <no...@non.net> wrote in message news:k3u6va$mb7$1...@speranza.aioe.org...
This is a function from Communications Toolbox.

http://www.mathworks.com/help/comm/ref/berawgn.html

Try using this data set instead:

ber = hex2num([...
'3fc0b8f566cdd976';
'3fba8ff4c3c84bc4';
'3fb4226162fbddd5';
'3facd0fcee304688';
'3fa33400d566ff21';
'3f976d6ff109a592';
'3f899a076544060a';
'3f7863150af37569';
'3f63909bd984aac4';
'3f4951aa87ffc76f';
'3f2905cd4adbd8c1';
'3f01a15ec5420bd0';
'3ed03da5007240da']).';

To the OP: what it sounds like you may be looking for is an errorbar plot
where the data is in log scale but the error bars are in linear scale. If
that's the case, I don't know of any plotting function that will do what
you're looking for.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Elnaz

unread,
Sep 26, 2012, 10:26:08 AM9/26/12
to
Actually, when I plot with errorbar and then change the scale to logarithmic, it only shows the upperbounds and a warning message that negative data are ignored.

Elnaz

dpb

unread,
Sep 26, 2012, 10:26:33 AM9/26/12
to
On 9/25/2012 11:08 PM, Elnaz wrote:
...

>
> a) This should do it:
> ber = berawgn(-2:10,'oqpsk','nondiff');
> pl =[0.886482908609522 0.886482908609522 0.886482908609522
> 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522
> 0.886482908609522 0.886482908609522 0.886482908609522 0.886482908609522
> 0.886482908609522 0.166645626439589];
> pu =[1 1 1 1 1 1 1 1 1 1 1 1 0.478761210116602];
>
> errorbar(-2:10,10*log10(ber),pl,pu);
> set(gca,'yscale','log');
>
> b&c) I expect to get a curve with error bars as this one:
> errorbar(-2:10,10*log10(ber),pl,pu);

> ber = [0.13 0.10 0.078
> 0.056 0.037 0.022
> 0.012 0.0059 0.0023
> 0.00077 0.00019 3.36e-05 3.87e-06];

OK, your expectations are out of line w/ reality in expecting anything
at all like that w/ simply changing the linear axis to log...

Look at the values you passed errorbar()...

>> [ber+pu ber-pl]
ans =
1.1306 -0.7554
1.1037 -0.7823
1.0786 -0.8074
1.0560 -0.8300
1.0375 -0.8485
1.0228 -0.8632
1.0125 -0.8735
1.0059 -0.8801
1.0024 -0.8836
1.0008 -0.8852
1.0002 -0.8858
1.0000 -0.8860
1.0000 -0.4800
>>

What's log10(negative value) ??? I'm not familiar w/ the Wilson score
interval altho the code looks like +/-2Z but clearly returning a
negative value is in error (as I presume is >1).

Oh, just had a thought--perhaps the reason the dB plot looks reasonable
is that the error score is already in dB and by using errorbar() w/ the
ber value and it you've mixed metaphors, so to speak. Either way,
something isn't kosher when you get the above limits...

If you want the scale in dB then you'll have to compute the dB
transformation--as your argument shows, it isn't _just_ the log scale
change.

Changing scale on errorbar() isn't "messed up"; it's doing what it's
asked to do. It's just that isn't what you want/need.

--

dpb

unread,
Sep 26, 2012, 10:35:00 AM9/26/12
to
Well, what do you expect log(negative_value) to be/errorbar() to do?

See other posting--short story is your expectations are flawed, not
errorbar()

--

dpb

unread,
Sep 26, 2012, 1:08:52 PM9/26/12
to
On 9/26/2012 9:26 AM, dpb wrote:
> On 9/25/2012 11:08 PM, Elnaz wrote:
> ...
...

>> b&c) I expect to get a curve with error bars as this one:
>> errorbar(-2:10,10*log10(ber),pl,pu);
...

> Oh, just had a thought--perhaps the reason the dB plot looks reasonable
> is that the error score is already in dB and by using errorbar() w/ the
> ber value and it you've mixed metaphors, so to speak. Either way,
> something isn't kosher when you get the above limits...
>
> If you want the scale in dB then you'll have to compute the dB
> transformation--as your argument shows, it isn't _just_ the log scale
> change.
...

Indeed, playing around w/ your data indicates that _is_ what's the
problem...

Given the above ber and [pl pu] vectors, try this...

>> dB=10*log10(ber);
>> berl=10.^((db-pl)/10);
>> beru=10.^((db+pu)/10);
>> dbel=ber-berl;
>> dbeu=beru-ber;
>> errorbar(-2:10,ber,dbel,dbeu)
>> set(gca,'yscale','log')
>>

See if that isn't what you were looking for.

Note that there's no way to get to the fixed-range error values in the
log scale for errorbar w/ it's linear plus/minus w/o converting the dB
levels to absolute and computing the delta. Your previous postings
clearly were mixing up the two scales...

--

Elnaz

unread,
Sep 26, 2012, 1:18:07 PM9/26/12
to
dpb <no...@non.net> wrote in message <k3v3r2$69o$1...@speranza.aioe.org>...
Yes dpb. You are absolutely right. There is a problem with the lower and upper bounds themselves. The confidence interval is so big that the lower bars fall into the negative values. I didn't realized that before. It isn't a plotting problem.
Thank you for your replies.

Elnaz

Michael

unread,
Oct 24, 2013, 6:46:09 AM10/24/13
to
dpb <no...@non.net> wrote in message <k3vcr9$v4o$1...@speranza.aioe.org>...
This really helped me plotting errorbars for decibel data - thanks!
0 new messages