Discussion:
plotting x-y error bars in IDL
(too old to reply)
Madhavan Bomidi
2013-12-06 10:24:35 UTC
Permalink
Hello,

Is it possible to make x-y error bars in the IDL plot? I have seen the example for including the y-errorbars but how to do this for including the x-errorbar. Any sample example will be helpful.

Thanks
wlandsman
2013-12-06 13:04:06 UTC
Permalink
You could try

http://idlastro.gsfc.nasa.gov/ftp/pro/plot/ploterror.pro
Post by Madhavan Bomidi
Hello,
Is it possible to make x-y error bars in the IDL plot? I have seen the example for including the y-errorbars but how to do this for including the x-errorbar. Any sample example will be helpful.
Thanks
David Fanning
2013-12-06 13:10:39 UTC
Permalink
Post by Madhavan Bomidi
Is it possible to make x-y error bars in the IDL plot? I have seen the example for including the y-errorbars but how to do this for including the x-errorbar. Any sample example will be helpful.
Yes.

http://www.idlcoyote.com/graphics_tips/yerrorbars.html

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.")
David Fanning
2013-12-06 14:16:39 UTC
Permalink
Post by David Fanning
Post by Madhavan Bomidi
Is it possible to make x-y error bars in the IDL plot? I have seen the example for including the y-errorbars but how to do this for including the x-errorbar. Any sample example will be helpful.
Yes.
http://www.idlcoyote.com/graphics_tips/yerrorbars.html
Oh, and, duh, cgErrPlot allows you to create both horizontal and
vertical error bars. :-)

http://www.idlcoyote.com/idldoc/cg/cgerrplot.html

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.")
David Grier
2013-12-09 02:30:09 UTC
Permalink
Post by David Fanning
Post by David Fanning
Post by Madhavan Bomidi
Is it possible to make x-y error bars in the IDL plot? I have seen the example for including the y-errorbars but how to do this for including the x-errorbar. Any sample example will be helpful.
Yes.
http://www.idlcoyote.com/graphics_tips/yerrorbars.html
Oh, and, duh, cgErrPlot allows you to create both horizontal and
vertical error bars. :-)
http://www.idlcoyote.com/idldoc/cg/cgerrplot.html
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.")
IDL's function graphics routine ERRORPLOT can plot both x and y error bars.
It even allows for asymmetric error bars.

All the best,

David
David Fanning
2013-12-09 02:45:31 UTC
Permalink
Post by David Grier
IDL's function graphics routine ERRORPLOT can plot both x and y error bars.
It even allows for asymmetric error bars.
Yes, asymmetric error bars are de rigueur:

http://www.idlcoyote.com/gallery/index.html#ERRORBAR_PLOT

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.")
Madhavan Bomidi
2013-12-09 10:10:59 UTC
Permalink
Hello All,

Thanks for the suggestions. I have an array of latitude, longitude coordinates from GPS measurements from various stations with corresponding variability (i.e., standard deviation) over a period of operation. I am trying to plot the errorbars of latitude and longitude on a latitude-longitude axes. I am first obtaining the latitude-longitude axes and then projecting the lat-lon points. Next, I wanted to plot the errorbars corresponding to lat and lon values by using the commands as suggested in the example of Coyote graphics. While I see the figures and the points on the lat-lon axes nicely, I don't see the error bars and x-y labels. Can you suggest where I am going wrong? Below is my IDL code for your reference...

; ---------------------------------------------
PRO test_errorPlot

xlon = longitude
ylat = latitude
xstd = lon_err & ystd = lat_err

x_higherr=(xlon + xstd) & x_lowerr=(xlon - xstd)
y_higherr=(ylat + ystd) & y_lowerr=(ylat - ystd)

; Set up variables for the plot
xtitle='Longitude'
ytitle='Latitude'
title='Errorbar Plot'
position = [0.125, 0.125, 0.9, 0.925]
thick = (!D.Name EQ 'PS') ? 3 : 1

; Data Projection to Map coordinates
Lats=[50.84D,50.96D] ; deg.N
Lons=[6.36D,6.50D] ; deg E
centerLat=(Max(Lats) + Min(Lats)) / 2.0
centerLon=(Max(Lons) + Min(Lons)) / 2.0
zoom=12
scale = cgGoogle_MetersPerPixel(zoom)
xsize = 600 < 640 ; Max size of Google image with this Google API
ysize = 600 < 640 ; Max size of Google image with this Google API
resolution = STRTRIM(xsize,2) + 'x' + STRTRIM(ysize,2)

map = Obj_New('cgMap', 'Mercator', ELLIPSOID='WGS 84')
uv = map -> Forward(centerLon, centerLat)
uv_xcenter = uv[0,0]
uv_ycenter = uv[1,0]
xrange = [uv_xcenter - (xsize/2.0D*scale), uv_xcenter + (xsize/2.0D*scale)]
yrange = [uv_ycenter - (ysize/2.0D*scale), uv_ycenter + (ysize/2.0D*scale)]
map -> SetProperty, XRANGE=xrange, YRANGE=yrange

cgDisplay, 600, 500, Title=title

cgMap_Grid, MAP=map, /BOX_AXES, /cgGRID, FORMAT='(F0.2)'

cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'

; Draw the error bars in the signal Y
cgErrPlot, xlon, y_lowerr, y_higherr, COLOR='blu5',Thick=thick

; Draw the error bars in the signal X
cgErrPlot, ylat, x_lowerr, x_higherr, COLOR='blu5',Thick=thick, /Horizontal

END

; Display the plot in a graphics window.
cgDisplay, 600, 500
test_errorPlot

; Create a PostScript file.
cgPS_Open, Filename='test_errorPlot.ps'
test_errorPlot
cgPS_Close

; Create a PNG file with a width of 600 pixels.
cgPS2Raster, 'test_errorPlot.ps', /PNG

END

;-------------------------------------

Thanks in advance
David Fanning
2013-12-09 13:33:16 UTC
Permalink
Post by Madhavan Bomidi
Hello All,
Thanks for the suggestions. I have an array of latitude, longitude coordinates from GPS measurements from various stations with corresponding variability (i.e., standard deviation) over a period of operation. I am trying to plot the errorbars of latitude and longitude on a latitude-longitude axes. I am first obtaining the latitude-longitude axes and then projecting the lat-lon points. Next, I wanted to plot the errorbars corresponding to lat and lon values by using the
commands as suggested in the example of Coyote graphics. While I see the figures and the points on the lat-lon axes nicely, I don't see the error bars and x-y labels. Can you suggest where I am going wrong? Below is my IDL code for your reference...

You have:

; Draw the error bars in the signal Y
cgErrPlot, xlon, y_lowerr, y_higherr, COLOR='blu5',Thick=thick

; Draw the error bars in the signal X
cgErrPlot, ylat, x_lowerr, x_higherr, COLOR='blu5',Thick=thick, $
/Horizontal

I think these should be:

; Draw the error bars in the signal Y
cgErrPlot, xlon, xlat-y_lowerr, xlat+y_higherr, $
COLOR='blu5',Thick=thick

; Draw the error bars in the signal X
cgErrPlot, ylat, xlon-x_lowerr, xlon+x_higherr, $
COLOR='blu5',Thick=thick, /Horizontal

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.")
Madhavan Bomidi
2013-12-09 17:58:07 UTC
Permalink
Hello David,

I have already defined in the beginning of my IDL code as:
x_lowerr = (xlon-xstd) & x_higherr = (xlon+xstd)
y_lowerr = (ylat-ystd) & y_higherr = (ylat+ystd)

So, I have used x_lowerr, x_higherr, y_lowerr, y_higherr directly. I don't understand what is going wrong and why I am not able to see both the errorbars?

Thanks...
Post by Madhavan Bomidi
Post by Madhavan Bomidi
Hello All,
Thanks for the suggestions. I have an array of latitude, longitude coordinates from GPS measurements from various stations with corresponding variability (i.e., standard deviation) over a period of operation. I am trying to plot the errorbars of latitude and longitude on a latitude-longitude axes. I am first obtaining the latitude-longitude axes and then projecting the lat-lon points. Next, I wanted to plot the errorbars corresponding to lat and lon values by using the
commands as suggested in the example of Coyote graphics. While I see the figures and the points on the lat-lon axes nicely, I don't see the error bars and x-y labels. Can you suggest where I am going wrong? Below is my IDL code for your reference...
; Draw the error bars in the signal Y
cgErrPlot, xlon, y_lowerr, y_higherr, COLOR='blu5',Thick=thick
; Draw the error bars in the signal X
cgErrPlot, ylat, x_lowerr, x_higherr, COLOR='blu5',Thick=thick, $
/Horizontal
; Draw the error bars in the signal Y
cgErrPlot, xlon, xlat-y_lowerr, xlat+y_higherr, $
COLOR='blu5',Thick=thick
; Draw the error bars in the signal X
cgErrPlot, ylat, xlon-x_lowerr, xlon+x_higherr, $
COLOR='blu5',Thick=thick, /Horizontal
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.")
David Fanning
2013-12-09 19:23:00 UTC
Permalink
Post by Madhavan Bomidi
x_lowerr = (xlon-xstd) & x_higherr = (xlon+xstd)
y_lowerr = (ylat-ystd) & y_higherr = (ylat+ystd)
So, I have used x_lowerr, x_higherr, y_lowerr, y_higherr directly. I don't understand what is going wrong and why I am not able to see both the errorbars?
Oh, I see. Sorry, I didn't see that before.

OK, what is happening here is that your latitude and longitude values
are being converted into XY projected meter space when you are plotting
them on your map. You are passing your map coordinate object into
cgPlotS so it can convert lon/lat values to XY values. cgErrPlot doesn't
know anything about this. So it is plotting lon/lat values on a plot
whose data range is many magnitudes greater than this.

Sigh...

I did the expedient thing instead of the right thing when I created
cgErrPlot and just made the IDL ErrPlot work in the Coyote Graphics
system. I knew at the time, just looking at how the parameters we so
screwy, that this was a bad idea. I don't know how Coyote convinced me
to do it, but he did.

This really should be re-written in the right way. Then, I could simply
add a MAP keyword to do the conversions internally and be done with it.
But... sigh.

The problem, really, is that I never envisoned using cgErrPlot on a map.
Lack of imagination, I guess.

Well, the solution, I suppose, it to just convert your lat and lon
values, and their associated errors into XY projected meter space. This
can be done with the map object.

xy = map -> Inverse(xlon, xlat)
lon = Reform(xy[0,*])
lat = Reform(xy[1,*])

xyhigh = map -> Inverse(y_higherr, xlat)
xylow = map -> Inverse(y_lowerr, xlat)
lon_high = Reform(xyhigh[0,*])
lon_low = Reform(xylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick

xyhigh = map -> Inverse(xlon, x_higherr)
xylow = map -> Inverse(xlon, x_lowerr)
lat_high = Reform(xyhigh[0,*])
lat_low = Reform(xylow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horiz

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.")
Madhavan Bomidi
2013-12-10 10:05:42 UTC
Permalink
Hello,

As suggested, I replaced the following lines in my code, I don't see even lat-lon points that I was able to see earlier. Now, I see only a black grid map with lat-lon axes. I still don't understand why to invert the data and why no display of points or error bars???

xy = map -> Inverse(xlon,ylat)
lon = REFORM(xy[0,*]) & lat = REFORM(xy[1,*])
cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'

; Draw the error bars in the signal Y
yhigh = map -> Inverse(y_higherr, ylat)
ylow = map -> Inverse(y_lowerr, ylat)

lon_high = REFORM(yhigh[0,*])
lon_low = REFORM(ylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick

; Draw the error bars in the signal X
xhigh = map -> Inverse(xlon, x_higherr)
xlow = map -> Inverse(xlon, x_lowerr)
lat_high = REFORM(xhigh[0,*])
lat_low = REFORM(xlow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horizontal


Thanks in advance.
David Fanning
2013-12-10 10:37:12 UTC
Permalink
Post by Madhavan Bomidi
As suggested, I replaced the following lines in my code, I don't see
even lat-lon points that I was able to see earlier. Now, I see only a
black grid map with lat-lon axes. I still don't understand why to invert
the data and why no display of points or error bars???
Post by Madhavan Bomidi
xy = map -> Inverse(xlon,ylat)
lon = REFORM(xy[0,*]) & lat = REFORM(xy[1,*])
cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'
; Draw the error bars in the signal Y
yhigh = map -> Inverse(y_higherr, ylat)
ylow = map -> Inverse(y_lowerr, ylat)
lon_high = REFORM(yhigh[0,*])
lon_low = REFORM(ylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick
; Draw the error bars in the signal X
xhigh = map -> Inverse(xlon, x_higherr)
xlow = map -> Inverse(xlon, x_lowerr)
lat_high = REFORM(xhigh[0,*])
lat_low = REFORM(xlow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horizontal
Thanks in advance.
Not sure what I was smoking yesterday (or maybe it is just the cloud
from OTHER people smoking here in Colordao), but all of those "Inverse"
calls should be changed to "Forward" calls. Sheesh. I guess I've never
seen map projections before. :-(

It is hard to write code without having data to run with it. I'm just
like everyone else, I make all KINDS of errors.

xy = map -> Forward(xlon,ylat)
lon = REFORM(xy[0,*]) & lat = REFORM(xy[1,*])
cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'

; Draw the error bars in the signal Y
yhigh = map -> Forward(y_higherr, ylat)
ylow = map -> Forward(y_lowerr, ylat)

lon_high = REFORM(yhigh[0,*])
lon_low = REFORM(ylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick

; Draw the error bars in the signal X
xhigh = map -> Forward(xlon, x_higherr)
xlow = map -> Forward(xlon, x_lowerr)
lat_high = REFORM(xhigh[0,*])
lat_low = REFORM(xlow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horiz

Let me know if that works better. If not, I'll probably just rewrite
cgErrPlot. In fact, I may do that anyway. It is a total mess. I should
never have based it on the IDL routine of the same name. :-(

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.")
Madhavan Bomidi
2013-12-10 11:00:06 UTC
Permalink
Sorry for all the troubles.

I don't see my (lon,lat) points on the plot. While I see x-errorbars, I don't see the y-errorbars at all. I don't have any clue what is happening ...

Thanks in advance ...
Post by Madhavan Bomidi
Post by Madhavan Bomidi
As suggested, I replaced the following lines in my code, I don't see
even lat-lon points that I was able to see earlier. Now, I see only a
black grid map with lat-lon axes. I still don't understand why to invert
the data and why no display of points or error bars???
Post by Madhavan Bomidi
xy = map -> Inverse(xlon,ylat)
lon = REFORM(xy[0,*]) & lat = REFORM(xy[1,*])
cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'
; Draw the error bars in the signal Y
yhigh = map -> Inverse(y_higherr, ylat)
ylow = map -> Inverse(y_lowerr, ylat)
lon_high = REFORM(yhigh[0,*])
lon_low = REFORM(ylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick
; Draw the error bars in the signal X
xhigh = map -> Inverse(xlon, x_higherr)
xlow = map -> Inverse(xlon, x_lowerr)
lat_high = REFORM(xhigh[0,*])
lat_low = REFORM(xlow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horizontal
Thanks in advance.
Not sure what I was smoking yesterday (or maybe it is just the cloud
from OTHER people smoking here in Colordao), but all of those "Inverse"
calls should be changed to "Forward" calls. Sheesh. I guess I've never
seen map projections before. :-(
It is hard to write code without having data to run with it. I'm just
like everyone else, I make all KINDS of errors.
xy = map -> Forward(xlon,ylat)
lon = REFORM(xy[0,*]) & lat = REFORM(xy[1,*])
cgPlotS, xlon, ylat, PSYM=16, SYMSIZE=1.2, MAP=map, COLOR='red'
; Draw the error bars in the signal Y
yhigh = map -> Forward(y_higherr, ylat)
ylow = map -> Forward(y_lowerr, ylat)
lon_high = REFORM(yhigh[0,*])
lon_low = REFORM(ylow[0,*])
cgErrPlot, lon, lon_high, lon_low, COLOR='blu5',Thick=thick
; Draw the error bars in the signal X
xhigh = map -> Forward(xlon, x_higherr)
xlow = map -> Forward(xlon, x_lowerr)
lat_high = REFORM(xhigh[0,*])
lat_low = REFORM(xlow[0,*])
cgErrPlot, lat, lat_high, lat_low, COLOR='blu5',Thick=thick, /Horiz
Let me know if that works better. If not, I'll probably just rewrite
cgErrPlot. In fact, I may do that anyway. It is a total mess. I should
never have based it on the IDL routine of the same name. :-(
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.")
David Fanning
2013-12-10 11:07:33 UTC
Permalink
Post by Madhavan Bomidi
Sorry for all the troubles.
I don't see my (lon,lat) points on the plot. While I see x-errorbars, I don't see the y-errorbars at all. I don't have any clue what is happening ...
You're the one with troubles. Send me some data to work with, I'll see
if I can figure it out. An IDL save file will work.

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.")
Madhavan Bomidi
2013-12-10 11:20:26 UTC
Permalink
I sent a sample data file to your email. Please check that ...
Post by David Fanning
Post by Madhavan Bomidi
Sorry for all the troubles.
I don't see my (lon,lat) points on the plot. While I see x-errorbars, I don't see the y-errorbars at all. I don't have any clue what is happening ...
You're the one with troubles. Send me some data to work with, I'll see
if I can figure it out. An IDL save file will work.
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.")
David Fanning
2013-12-10 19:14:01 UTC
Permalink
Post by Madhavan Bomidi
I don't see my (lon,lat) points on the plot. While I see x-errorbars, I don't see the y-errorbars at all. I don't have any clue what is happening ...
In your case the errors are so small that even if we can draw the error
bars correctly, they would be completely overwhelmed by the size of the
symbol you are using to represent the point itself. Even if you plot a
line of data with the error lines above and below, it all appears as a
single line on the plot. Essentially, there is no difference between the
data and the data plus or minus the extremely small error.

Cheers,

David

P.S. See the announcement in this group for new error bar handling in
Coyote Graphics routines.
--
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.")
Madhavan Bomidi
2013-12-11 09:48:14 UTC
Permalink
Hello David,

I do agree with your suggestion and thanks for updating the cgplot.pro with more keywords including the errorbar options.

Regards ...
Post by David Fanning
Post by Madhavan Bomidi
I don't see my (lon,lat) points on the plot. While I see x-errorbars, I don't see the y-errorbars at all. I don't have any clue what is happening ...
In your case the errors are so small that even if we can draw the error
bars correctly, they would be completely overwhelmed by the size of the
symbol you are using to represent the point itself. Even if you plot a
line of data with the error lines above and below, it all appears as a
single line on the plot. Essentially, there is no difference between the
data and the data plus or minus the extremely small error.
Cheers,
David
P.S. See the announcement in this group for new error bar handling in
Coyote Graphics routines.
--
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.")
Loading...