comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Displaced errorbars on log-log scale with cgPlot
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Displaced errorbars on log-log scale with cgPlot [message #90098] Tue, 27 January 2015 02:20 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I was using cgPlot to make the line plot on a log-log scale. I have included the y-axis errors around each data point. I have followed the Coyote Graphics Gallery - 'Error bar plot'. In my plot, I found that for some points the error bars are displaced and above the data point. I guess this is a bug in log-log scaling of error bars!!!

Thanks in advance,
Madhavan
Re: Displaced errorbars on log-log scale with cgPlot [message #90099 is a reply to message #90098] Tue, 27 January 2015 05:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> I was using cgPlot to make the line plot on a log-log scale. I have included the y-axis errors around each data point. I have followed the Coyote Graphics Gallery - 'Error bar plot'. In my plot, I found that for some points the error bars are displaced and above the data point. I guess this is a bug in log-log scaling of error bars!!!

It seems unlikely in the absences of evidence. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Displaced errorbars on log-log scale with cgPlot [message #90112 is a reply to message #90099] Wed, 28 January 2015 07:25 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello David,

Please check the below code and the resulting output:

---------------------------------
PRO testerr

xdt = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]


ymean = [ 5.7071102e-07, 1.9411492e-07, 2.4366391e-07, 3.9646722e-07, $
8.8304703e-07, 3.6161633e-06, 1.5931371e-05, 6.4912913e-05, $
0.00019788680, 0.00042545785, 0.00033186864, 0.00031074151 ]

ystd = [ 4.1662774e-07, 2.7208043e-07, 4.5170846e-07, 7.2870838e-07, $
1.2310552e-06, 3.6163696e-06, 1.4698943e-05, 6.3878156e-05, $
0.00023048977, 0.00053752256, 0.00033514162, 0.00018645177 ]

low_yerr = (ymean - ystd)
high_yerr = (ymean + ystd)

FigFile = 'testerrplot.ps'

cgPS_Open,FigFile
cgDisplay

cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
CharSize=1.2, ERR_YLow=low_yerr, $
ERR_YHigh=high_yerr, Psym=-16, $
ERR_Color='red7',SymColor='red7',Color='red7'

cgPS_Close

; Create a PNG file
cgPS2Raster,FigFile,/PNG

END
--------------------------------------

Thanks in advance,
Regards,
Madhavan
Re: Displaced errorbars on log-log scale with cgPlot [message #90113 is a reply to message #90112] Wed, 28 January 2015 07:53 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Wednesday, January 28, 2015 at 4:25:24 PM UTC+1, Madhavan Bomidi wrote:
> Hello David,
>
> Please check the below code and the resulting output:
>
> ---------------------------------
> PRO testerr
>
> xdt = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
>
>
> ymean = [ 5.7071102e-07, 1.9411492e-07, 2.4366391e-07, 3.9646722e-07, $
> 8.8304703e-07, 3.6161633e-06, 1.5931371e-05, 6.4912913e-05, $
> 0.00019788680, 0.00042545785, 0.00033186864, 0.00031074151 ]
>
> ystd = [ 4.1662774e-07, 2.7208043e-07, 4.5170846e-07, 7.2870838e-07, $
> 1.2310552e-06, 3.6163696e-06, 1.4698943e-05, 6.3878156e-05, $
> 0.00023048977, 0.00053752256, 0.00033514162, 0.00018645177 ]
>
> low_yerr = (ymean - ystd)
> high_yerr = (ymean + ystd)
>
> FigFile = 'testerrplot.ps'
>
> cgPS_Open,FigFile
> cgDisplay
>
> cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
> XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
> CharSize=1.2, ERR_YLow=low_yerr, $
> ERR_YHigh=high_yerr, Psym=-16, $
> ERR_Color='red7',SymColor='red7',Color='red7'
>
> cgPS_Close
>
> ; Create a PNG file
> cgPS2Raster,FigFile,/PNG
>
> END
> --------------------------------------
>
> Thanks in advance,
> Regards,
> Madhavan

Hi,
that's because the errors are automatically added to the y values. According to David's documentation:

; err_yhigh: in, optional
; The high error values that should be added to the dependent or Y data values.
; err_ylow: in, optional
; The low error values that should be subtracted from the dependent or Y data values.

therefore if you change:
low_yerr = (ymean - ystd)
high_yerr = (ymean + ystd)
to
low_yerr = ystd
high_yerr = ystd

Then comes the real problem... Did you look at the numbers? So here it goes:
1.54083e-007
-7.79655e-008
-2.08045e-007
-3.32241e-007
-3.48008e-007
-2.06455e-010
1.23243e-006
1.03476e-006
-3.26030e-005
-0.000112065
-3.27296e-006
0.000124290

Now the graphics has to place errorbars for negative values. If you select only positive values (4 of them), the plot looks fine:

goodVals = where(ymean-ystd gt 0.0, cnt)
ymean = ymean[goodVals]
ystd = ystd[goodVals]
xdt = xdt[goodVals]
cgDisplay, 600, 600, WID=1, Title='log-log'
cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
CharSize=1.2, ERR_YLow=ystd, $
ERR_YHigh=ystd, Psym=-16, $
ERR_Color='red7',SymColor='red7',Color='red7'

Cheers,
Helder
Re: Displaced errorbars on log-log scale with cgPlot [message #90114 is a reply to message #90113] Wed, 28 January 2015 07:55 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Wednesday, January 28, 2015 at 4:54:01 PM UTC+1, Helder wrote:
> On Wednesday, January 28, 2015 at 4:25:24 PM UTC+1, Madhavan Bomidi wrote:
>> Hello David,
>>
>> Please check the below code and the resulting output:
>>
>> ---------------------------------
>> PRO testerr
>>
>> xdt = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
>>
>>
>> ymean = [ 5.7071102e-07, 1.9411492e-07, 2.4366391e-07, 3.9646722e-07, $
>> 8.8304703e-07, 3.6161633e-06, 1.5931371e-05, 6.4912913e-05, $
>> 0.00019788680, 0.00042545785, 0.00033186864, 0.00031074151 ]
>>
>> ystd = [ 4.1662774e-07, 2.7208043e-07, 4.5170846e-07, 7.2870838e-07, $
>> 1.2310552e-06, 3.6163696e-06, 1.4698943e-05, 6.3878156e-05, $
>> 0.00023048977, 0.00053752256, 0.00033514162, 0.00018645177 ]
>>
>> low_yerr = (ymean - ystd)
>> high_yerr = (ymean + ystd)
>>
>> FigFile = 'testerrplot.ps'
>>
>> cgPS_Open,FigFile
>> cgDisplay
>>
>> cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
>> XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
>> CharSize=1.2, ERR_YLow=low_yerr, $
>> ERR_YHigh=high_yerr, Psym=-16, $
>> ERR_Color='red7',SymColor='red7',Color='red7'
>>
>> cgPS_Close
>>
>> ; Create a PNG file
>> cgPS2Raster,FigFile,/PNG
>>
>> END
>> --------------------------------------
>>
>> Thanks in advance,
>> Regards,
>> Madhavan
>
> Hi,
> that's because the errors are automatically added to the y values. According to David's documentation:
>
> ; err_yhigh: in, optional
> ; The high error values that should be added to the dependent or Y data values.
> ; err_ylow: in, optional
> ; The low error values that should be subtracted from the dependent or Y data values.
>
> therefore if you change:
> low_yerr = (ymean - ystd)
> high_yerr = (ymean + ystd)
> to
> low_yerr = ystd
> high_yerr = ystd
>
> Then comes the real problem... Did you look at the numbers? So here it goes:
> 1.54083e-007
> -7.79655e-008
> -2.08045e-007
> -3.32241e-007
> -3.48008e-007
> -2.06455e-010
> 1.23243e-006
> 1.03476e-006
> -3.26030e-005
> -0.000112065
> -3.27296e-006
> 0.000124290
>
> Now the graphics has to place errorbars for negative values. If you select only positive values (4 of them), the plot looks fine:
>
> goodVals = where(ymean-ystd gt 0.0, cnt)
> ymean = ymean[goodVals]
> ystd = ystd[goodVals]
> xdt = xdt[goodVals]
> cgDisplay, 600, 600, WID=1, Title='log-log'
> cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
> XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
> CharSize=1.2, ERR_YLow=ystd, $
> ERR_YHigh=ystd, Psym=-16, $
> ERR_Color='red7',SymColor='red7',Color='red7'
>
> Cheers,
> Helder

Ups... a line went missing.
The values showed are a result of
print, ymean-ystd
1.54083e-007
-7.79655e-008
-2.08045e-007
-3.32241e-007
-3.48008e-007
-2.06455e-010
1.23243e-006
1.03476e-006
-3.26030e-005
-0.000112065
-3.27296e-006
0.000124290

sorry for missing that.

Cheers,
Helder
Re: Displaced errorbars on log-log scale with cgPlot [message #90115 is a reply to message #90112] Wed, 28 January 2015 07:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

>
> Hello David,
>
> Please check the below code and the resulting output:
>
> ---------------------------------
> PRO testerr
>
> xdt = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
>
>
> ymean = [ 5.7071102e-07, 1.9411492e-07, 2.4366391e-07, 3.9646722e-07, $
> 8.8304703e-07, 3.6161633e-06, 1.5931371e-05, 6.4912913e-05, $
> 0.00019788680, 0.00042545785, 0.00033186864, 0.00031074151 ]
>
> ystd = [ 4.1662774e-07, 2.7208043e-07, 4.5170846e-07, 7.2870838e-07, $
> 1.2310552e-06, 3.6163696e-06, 1.4698943e-05, 6.3878156e-05, $
> 0.00023048977, 0.00053752256, 0.00033514162, 0.00018645177 ]
>
> low_yerr = (ymean - ystd)
> high_yerr = (ymean + ystd)
>
> FigFile = 'testerrplot.ps'
>
> cgPS_Open,FigFile
> cgDisplay
>
> cgPlot,xdt,ymean, Font=-1,/XLOG,XStyle=1,YStyle=1, $
> XRange=[100000,1],YRange=[0.000000001,0.1], /YLOG, $
> CharSize=1.2, ERR_YLow=low_yerr, $
> ERR_YHigh=high_yerr, Psym=-16, $
> ERR_Color='red7',SymColor='red7',Color='red7'
>
> cgPS_Close
>
> ; Create a PNG file
> cgPS2Raster,FigFile,/PNG
>
> END
> --------------------------------------

It appears to me you are giving me numbers that it is impossible to take
the log of:

IDL> print, alog10(low_yerr)
-6.81224 -NaN -NaN -NaN -NaN
-NaN -5.90924 -5.98516 -NaN
-NaN -NaN -3.90556

The "problem" values are those that can't be calculated.

I guess the real problem might be understanding why errors are not being
thrown by cgPlot. I'll look into it.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Contour annotations
Next Topic: Krig2d from point to image

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:23:42 PDT 2025

Total time taken to generate the page: 0.00575 seconds