err_bar.pro 3.28 KB
PRO err_bar,x,y,xrms=xrms,yrms=yrms,linestyle=linestyle,xbar=xbar,ybar=ybar, $
            color=color

;+
; NAME:
;       err_bar
; CALLING SEQUENCE:
;       err_bar,x,y
; PURPOSE:
;	overplot x and/or y error bars od size dx and dy
; INPUTS:
;       x,y         =points where errors must be plotted
; OPTIONAL INPUT:
;    xrms,yrms   = errors (will plot x+-xrms/2., y+-yrms/2.)
;	linestyle   = line style for error bars (default=0)
;	xbar,ybar   = size of the little bars (% of range)
; OUTPUTS:
;    None
; PROCEDURE AND SUBROUTINE USED
;	Straightforwrd
; SIDE EFFECTS:
;    None
; MODIFICATION HISTORY:
;    written JPB Jan-94
;-

;on_error,2

IF N_PARAMS(0) NE 2 THEN BEGIN
  print,'err_bar,x,y'
  print,'Accepted Key-Words: [,xrms=][,yrms=][,linestyle=]'
  print,'                    [xbar=][ybar=][color=color]'
  print,'Will plot x+-xrms/2.'
  print,'xbar & ybar in % of the range'
  GOTO,sortie
ENDIF

IF !x.type EQ 1 THEN xrg=10^!x.crange
IF !x.type EQ 0 THEN xrg=!x.crange
IF !y.type EQ 1 THEN yrg=10^!y.crange
IF !y.type EQ 0 THEN yrg=!y.crange

IF not keyword_set(xrms) AND not keyword_set(yrms) THEN BEGIN
  print,'One of xrms or yrms must be set'
  goto,sortie
ENDIF
sty=0
IF keyword_set(linestyle) NE 0 THEN BEGIN
  sty=linestyle
ENDIF

si=size(x)
npt=si(1)

old_psym=!psym
!psym=0

xmax=!x.crange(1)
xmin=!x.crange(0)
IF !x.type EQ 0 THEN BEGIN			;for linear plots
  xrange=xmax-xmin
  IF keyword_set(xbar) EQ 0 THEN BEGIN
    epsx=xrange/50.
  ENDIF ELSE BEGIN
    epsx=xbar/100.*xrange
  ENDELSE
ENDIF ELSE BEGIN				;for log
  xrange=xmax-xmin
  IF keyword_set(xbar) EQ 0 THEN BEGIN
    epsx=x*xrange/50.
  ENDIF ELSE BEGIN
    epsx=x*xbar/100.*xrange
;    epsx=10^(x*xbar/100.*xrange)
  ENDELSE
ENDELSE

ymax=!y.crange(1)
ymin=!y.crange(0)
yrange=ymax-ymin
IF !y.type EQ 0 THEN BEGIN
  IF keyword_set(ybar) EQ 0 THEN BEGIN
    epsy=yrange/50.
  ENDIF ELSE BEGIN  
    epsy=ybar/100.*yrange
  ENDELSE  
ENDIF ELSE BEGIN
  IF keyword_set(ybar) EQ 0 THEN BEGIN
    epsy=y*yrange/50.
  ENDIF ELSE BEGIN  
    epsy=y*ybar/100.*yrange
  ENDELSE  
ENDELSE
  
for j=0,npt-1 do begin
  IF keyword_set(xrms) NE 0 THEN BEGIN
    errbarx=[x(j)-xrms(j)/2.,x(j)+xrms(j)/2.]
    errbary=[y(j),y(j)]
    IF errbarx(0) LT 0 then errbarx(0)=xrg(0)
    IF errbarx(1) GT xrg(1) then errbarx(1)=xrg(1)
    oplot,errbarx,errbary,linestyle=sty,color=color
    IF !y.type EQ 0 THEN BEGIN
      eps=epsy
    ENDIF ELSE BEGIN
      eps=epsy(j)
    ENDELSE
    bout1x=[x(j)-xrms(j)/2.,x(j)-xrms(j)/2.]
    bout1y=[y(j)-eps,y(j)+eps]
    oplot,bout1x,bout1y,linestyle=sty,color=color
    bout1x=[x(j)+xrms(j)/2.,x(j)+xrms(j)/2.]
    bout1y=[y(j)-eps,y(j)+eps]
    oplot,bout1x,bout1y,linestyle=sty,color=color
  ENDIF
  IF keyword_set(yrms) NE 0 THEN BEGIN
    errbarx=[x(j),x(j)]
    errbary=[y(j)-yrms(j)/2.,y(j)+yrms(j)/2.]
    IF errbary(0) LT 0 then errbary(0)=yrg(0)
    IF errbary(1) GT yrg(1) then errbary(1)=yrg(1)
    oplot,errbarx,errbary,linestyle=sty,color=color
    IF !x.type EQ 0 THEN BEGIN
      eps=epsx
    ENDIF ELSE BEGIN
      eps=epsx(j)
    ENDELSE
    bout1x=[x(j)-eps,x(j)+eps]
    bout1y=[y(j)-yrms(j)/2.,y(j)-yrms(j)/2.]
    oplot,bout1x,bout1y,linestyle=sty,color=color
    bout1x=[x(j)-eps,x(j)+eps]
    bout1y=[y(j)+yrms(j)/2.,y(j)+yrms(j)/2.]
    oplot,bout1x,bout1y,linestyle=sty,color=color
  ENDIF
ENDFOR

!psym=old_psym

sortie:
END