X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4083 Rate this article:
No rating

Long error bars from ERRORPLOT are not clipped

Topic

Plotting error bars in the new graphics in IDL 8.0 and 8.1 can produce bars that extend beyond the limites of the plot axis.
The following tech tip explains a workaround for those who would like to see those error bars clipped just at the axis borderline.

Discussion

To produce error bars in a new graphics plot the following function can be used. for example:

non_cropped_plot = errorplot(y, y, yerrors, /histogram, color='green', yrange=[2,17])

But depending on the data set and the limits used to create the plot, error bars can end up crossing the limites of the plot. For example, here is a result that for some users is not acceptable:



errorbars_nocropping

Workaround

A simple workaround will be to limit the length of the error bars only to be such that they will fall inside the margins of the plot. The following example code shows how to do that (Note: Please see at the bottom of this article the editable version of this code):


errorbars_nocropping_code

The corresponding results of executing the above code is the following:



errorbars_cropping_ex


Solution

This is the editable version of the example code:

pro cropping_errorbars

y = findgen(20)
; An example of an array of errors. 
yerrors = reverse(y)

; The array HAS to be a 2xN, where N=ydim. Even though both dimensions
; are composed by the same elements (for a symetric error bars plot, 
; it has to be done so that we can use the asymetric error option in ERRORPLOT
; (see IDL Help on the errorplot() function):
yerror1 = transpose(reverse(y))
yerror2 = transpose(reverse(y))
yerror  = [yerror1,yerror2]
ydim=N_ELEMENTS(y)

; The Y range has to be fixed!:
ymax=17
ymin=2
yrange=ymax-ymin

p=plot(y, y, yrange=[ymin, ymax], /nodata)

;Cropping the error bars when they are longer than the Y range:
for i=0, ydim-1 do begin
  ;Positive error bar
  if (yerror[1,i] ge ymax-y[i]) then begin
    yerror[1,i]=ymax-y[i]
  endif
  
  ;Negative error bar
  if (yerror[0,i] ge y[i]-ymin) then begin
    yerror[0,i]=y[i]-ymin
  endif
endfor

cropped_plot = errorplot(y, y, yerror,color='red', /overplot, /histogram)
non_cropped_plot = errorplot(y, y,yerrors,/histogram,color='green', yrange=[2,17])

; Set some properties
cropped_plot.THICK=1
cropped_plot.SYM_COLOR ="cornflower"
cropped_plot.ERRORBAR_COLOR="indian_red"
cropped_plot.ERRORBAR_CAPSIZE=0.5

end
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »