Blame view

src/idl_misc/err_bar.pro 3.28 KB
427f1205   Jean-Michel Glorian   version 4.2 merged
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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