-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyplotbreak.pro
More file actions
156 lines (134 loc) · 4.29 KB
/
yplotbreak.pro
File metadata and controls
156 lines (134 loc) · 4.29 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
;;
;; NOTE: First draft. Seeking feedback or use cases.
;;
;+
;
; NAME:
; PLOTBREAK
;
; PURPOSE:
; Plot a data set with a break as per:
; http://groups.google.com/group/comp.lang.idl-pvwave/browse_frm/thread/ce29c1ba4693c373
; Should be a drop-in replacement for PLOT.
;
; CATEGORY:
; Plotting
;
; CALLING SEQUENCE:
; PLOTBREAK, X, Y
;
; INPUTS:
; X: an array, similar to what you might pass to PLOT
; Y: an array, similar to what you might pass to PLOT
;
; KEYWORD PARAMETERS:
; BREAKPCT: The percentage horizontally across the plot where the
; break should occur. Defaults to 50%
; GAP: The break size.
; VERTBAR: If a vertical bar should be drawn instead of "/" marks.
; XRANGE0: The xrange of the left part
; XRANGE1: The xrange of the right part
;
; Etc... more complete documentation to come as code matures.
;
; EXAMPLE:
; For now see testing code at bottom.
;
; MODIFICATION HISTORY:
; Written by: Ken Mankoff, 2010-04-03.
;
;-
pro plotbreak, x,y, $
breakpct=breakpct, $
gap=gap, $
vertbar=vertbar, $
yrange0=yrange0, yrange1=yrange1, $
title=title, xtitle=xtitle, $
position=position, $
_EXTRA_0=e0, _EXTRA_1=e1, $
_EXTRA=e
if not keyword_set(position) then position=[0.9,0.9,0.1,0.1]
if not keyword_set(breakpct) then breakpct=50
breakloc = (position[2]-position[0]) * (breakpct/100.)+position[0]
if n_elements(gap) eq 0 then gap = 0.01 ;kdm_isdefined, gap, default=0.01
if not keyword_set(yrange0) then yrange0=[0,max(y)/2.]
if not keyword_set(yrange1) then yrange1=[max(y)/2.,max(y)]
pos0 = [breakloc-gap,position[3],position[0],position[1]]
pos1 = [position[2],position[3],breakloc+gap,position[1]]
PRINT, 'pos=',pos0,pos1
xrange = minmax(x)
xrange = xrange + [-0.1,0.1]*(xrange[1]-xrange[0])
plot, x, y, $
position=pos0, $
yrange=yrange0, $
/xst, $
yst=9, $
xrange=xrange, $
_EXTRA=e0
if keyword_set(vertbar) then begin
plots, [breakloc,breakloc], [pos0[1],pos0[3]], $
/norm, color=254, linestyle=2, _EXTRA=e
endif
if not keyword_set( slashScaleV ) then slashScaleV = 2.5
if not keyword_set( slashScaleH ) then slashScaleH = 0.5
;; bottom left
slashL = convert_coord( pos0[2]-gap*slashScaleH, $
pos0[1]-gap*slashScaleV, /norm, /to_data )
slashR = convert_coord( pos0[2]+gap*slashScaleH, $
pos0[1]+gap*slashScaleV, /norm, /to_data )
plots, [slashL[0],slashR[0]], [slashL[1],slashR[1]]
;; bottom right
slashL = convert_coord( pos0[2]-gap*slashScaleH+(2*gap), $
pos0[1]-gap*slashScaleV, /norm, /to_data )
slashR = convert_coord( pos0[2]+gap*slashScaleH+(2*gap), $
pos0[1]+gap*slashScaleV, /norm, /to_data )
plots, [slashL[0],slashR[0]], [slashL[1],slashR[1]]
;; top left
slashL = convert_coord( pos0[2]-gap*slashScaleH, $
pos0[3]-gap*slashScaleV, /norm, /to_data )
slashR = convert_coord( pos0[2]+gap*slashScaleH, $
pos0[3]+gap*slashScaleV, /norm, /to_data )
plots, [slashL[0],slashR[0]], [slashL[1],slashR[1]]
;; top right
slashL = convert_coord( pos0[2]-gap*slashScaleH+(2*gap), $
pos0[3]-gap*slashScaleV, /norm, /to_data )
slashR = convert_coord( pos0[2]+gap*slashScaleH+(2*gap), $
pos0[3]+gap*slashScaleV, /norm, /to_data )
plots, [slashL[0],slashR[0]], [slashL[1],slashR[1]]
plot, x,y, $
/NOERASE, $
/yst, $
position=pos1, $
yrange=yrange1, $
xrange=xrange, $
xst=5, $
_EXTRA=e1
axis, /yaxis, /yst, _EXTRA=e1
;; title and xtitle
if keyword_set(title) then $
xyouts, (position[2]+position[0])/2., $ ; X
;position[3] + (position[1]+position[3])*.035, $
position[3] + 0.02, $
charsize=1.3, $
title, _EXTRA=e, /norm, align=0.5
if keyword_set(xtitle) then $
xyouts, (position[2]+position[0])/2., $ ; X
position[1] - 0.055, $
xtitle, _EXTRA=e, /norm, align=0.5
end
function minmax,array,subs,NAN=nan, DIMEN=dimen
On_error,2
compile_opt idl2
if N_elements(DIMEN) GT 0 then begin
amin = min(array, MAX = amax, NAN = nan, DIMEN = dimen,cmin,sub=cmax)
if arg_present(subs) then subs = transpose([[cmin], [cmax]])
return, transpose([[amin],[amax] ])
endif else begin
amin = min( array, MAX = amax, NAN=nan, cmin, sub=cmax)
if arg_present(subs) then subs = [cmin, cmax]
return, [ amin, amax ]
endelse
;; x = indgen(1000)
;; y = randomu(seed,1000)+x/250.
;; plotbreak, x, y
end