-
Notifications
You must be signed in to change notification settings - Fork 6
/
cbar.gs
94 lines (94 loc) · 2.03 KB
/
cbar.gs
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
*
* Script to plot a colorbar
*
* The script will assume a colorbar is wanted even if there is
* not room -- it will plot on the side or the bottom if there is
* room in either place, otherwise it will plot along the bottom and
* overlay labels there if any. This can be dealt with via
* the 'set parea' command. In version 2 the default parea will
* be changed, but we want to guarantee upward compatibility in
* sub-releases.
*
function colorbar (args)
*
* Check shading information
*
'query shades'
shdinfo = result
if (subwrd(shdinfo,1)='None')
say 'Cannot plot color bar: No shading information'
return
endif
*
* Get plot size info
*
'query gxinfo'
rec2 = sublin(result,2)
rec3 = sublin(result,3)
rec4 = sublin(result,4)
xsiz = subwrd(rec2,4)
ysiz = subwrd(rec2,6)
ylo = subwrd(rec4,4)
xhi = subwrd(rec3,6)
xd = xsiz - xhi
*
* Decide if horizontal or vertical color bar
* and set up constants.
*
if (ylo<0.6 & xd<1.0)
say "Not enough room in plot for a colorbar"
return
endif
cnum = subwrd(shdinfo,5)
if (ylo<0.6 | xd>1.5)
xl = xhi + xd/2 - 0.4
xr = xl + 0.2
xwid = 0.2
ywid = 0.5
if (ywid*cnum > ysiz*0.8)
ywid = ysiz*0.8/cnum
endif
ymid = ysiz/2
yb = ymid - ywid*cnum/2
'set string 1 l 5'
vert = 1
else
ymid = ylo/2
yt = ymid + 0.2
yb = ymid
xmid = xsiz/2
xwid = 0.8
if (xwid*cnum > xsiz*0.8)
xwid = xsiz*0.8/cnum
endif
xl = xmid - xwid*cnum/2
'set string 1 tc 5'
vert = 0
endif
*
* Plot colorbar
*
'set strsiz 0.12 0.13'
num = 0
while (num<cnum)
rec = sublin(shdinfo,num+2)
col = subwrd(rec,1)
hi = subwrd(rec,3)
'set line 'col
if (vert)
yt = yb + ywid
else
xr = xl + xwid
endif
'draw recf 'xl' 'yb' 'xr' 'yt
if (num<cnum-1)
if (vert)
'draw string '%(xr+0.05)%' 'yt' 'hi
else
'draw string 'xr' '%(yb-0.05)%' 'hi
endif
endif
num = num + 1
if (vert); yb = yt;
else; xl = xr; endif;
endwhile