-
Notifications
You must be signed in to change notification settings - Fork 15
/
func_plot_vertical_lines.ncl
85 lines (68 loc) · 2.21 KB
/
func_plot_vertical_lines.ncl
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
;;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
;;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
function create_std_xz_polygon(avgline[*],stdline[*],z[*])
begin
;; create polygon coordinate for gsn_polygon
;; avgline +- stdline in x,z asix
;; return coords(2,nz*2) for x,y
left = avgline-stdline
right = avgline+stdline
;;
x = array_append_record(left,right(::-1),0)
y = array_append_record(z,z(::-1),0)
dims = dimsizes(x)
coords = reshape(x,(/2,dims/))
coords(0,:) = tofloat(x)
coords(1,:) = tofloat(y)
return coords
end
function plot_vertical_lines(title[1]:string,filename[1]:string,x[*][*]:numeric,z[*]:numeric,ires)
begin
;; assume x is (nline,lev)
print(" plot vertical_lines: "+filename)
xdims = dimsizes(x)
nline = xdims(0)
nlev = xdims(1)
res = ires
res@gsnLeftString = title
res@trYReverse = True
if(isatt(res,"nostd"))then
nostd = res@nostd
delete(res@nostd)
else
nostd = False
end if
wks = gsn_open_wks("ps",filename)
if(nline.gt.100.and.(.not.nostd))then ;; too many lines, draw average line and std range
avgline = dim_avg_n(x,0)
stdline = dim_stddev_n(x,0)
std1poly = create_std_xz_polygon(avgline,stdline,z)
std2poly = create_std_xz_polygon(avgline,stdline*2,z)
res@gsnFrame = False
res@gsnDraw = False
res@xyLineColor = "black"
res@xyLineThicknessF = 3.0
plot = gsn_csm_xy(wks,avgline,z,res)
shadres = True
shadres@gsFillColor = "cyan"
gsn_polygon(wks,plot,std2poly(0,:),std2poly(1,:),shadres)
shadres@gsFillColor = "cyan4"
gsn_polygon(wks,plot,std1poly(0,:),std1poly(1,:),shadres)
;; add x = 0 ref line
yrefres = True
yrefres@gsLineColor = "red"
x0 = z*0
gsn_polyline(wks,plot,x0,z,yrefres)
draw(plot)
frame(wks)
return True
end if
plot = gsn_csm_xy(wks,x,z,res)
if(isatt(res,"gsnDraw").and.(.not.res@gsnDraw))then
draw(plot)
end if
if(isatt(res,"gsnFrame").and.(.not.res@gsnDraw))then
frame(wks)
end if
return True
end