cjs_draw_xy.ncl 4.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sub.cjs_draw_xy.ncl
; Carl Schreck (cjschrec@ncsu.edu)
; April 2014
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) 2010, North Carolina State University
; All rights reserved.
; This work licensed under BSD 3-Clause License. Full terms in LICENSE.txt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


undef ( "cjs_draw_xy" )
function cjs_draw_xy( \
  io_wks         [1] : graphic, \
  i_xData            : numeric, \
  i_yData            : numeric, \
  i_res          [1] : logical \
)
begin ; cjs_draw_xy
  ; These are some parameters that could be useful to have up top

22
23
24
25
26
27
  yDims = dimsizes(i_yData)
  xDims = dimsizes(i_xData)
  if( dimsizes(xDims).gt.1 )
    nCurves = xDims(0)
  else if( dimsizes(yDims).gt.1 ) then
    nCurves = yDims(0)
28
29
30
  else
    nCurves = 1
  end if
31
  end if
32
33

  ; Customize base plot
Carl Schreck's avatar
Carl Schreck committed
34
35
36
  res = cjs_fontHeightF( i_res )
  res@gsnDraw  := False
  res@gsnFrame := False
37
  if( isatt( i_yData, "long_name" ) ) then
Carl Schreck's avatar
Carl Schreck committed
38
    res@gsnLeftString  := i_yData@long_name
39
  end if
Carl Schreck's avatar
Carl Schreck committed
40
  res@gsnRightString := ""
41
42

  if( isatt( i_xData, "units" ) ) then
Carl Schreck's avatar
Carl Schreck committed
43
    res@tiXAxisString := i_xData@units
44
45
  end if
  if( isatt( i_yData, "units" ) ) then
Carl Schreck's avatar
Carl Schreck committed
46
    res@tiYAxisString := i_yData@units
47
48
  end if
  if( ( isatt( i_res, "tmYLLabelsOn" ) ).and.( .not.i_res@tmYLLabelsOn ) ) then
Carl Schreck's avatar
Carl Schreck committed
49
    res@tiYAxisString := ""
50
51
  end if
  if( ( isatt( i_res, "tmXBLabelsOn" ) ).and.( .not.i_res@tmXBLabelsOn ) ) then
Carl Schreck's avatar
Carl Schreck committed
52
    res@tiXAxisString := ""
53
54
55
  end if

  ; ...make gridlines look nice
Carl Schreck's avatar
Carl Schreck committed
56
57
58
59
  res@tmXMajorGridLineDashPattern := 2.
  res@tmYMajorGridLineDashPattern := 2.
  res@tmXMajorGridThicknessF      := 1.
  res@tmYMajorGridThicknessF      := 1.
60

Carl Schreck's avatar
Carl Schreck committed
61
  res@xyCurveDrawOrder := "PostDraw"
62
63

  ; ...set up an x-y line graph
Carl Schreck's avatar
Carl Schreck committed
64
65
66
67
68
69
  res@gsnYRefLine := 0
  res@gsnYRefLineColor := "black"
  res@gsnYRefLineThicknessF := 2
  res@gsnXRefLine := 0
  res@gsnXRefLineColor := "black"
  res@gsnXRefLineThicknessF := 2
70
  res@xyMarkLineMode      := "Lines"
71
  if( ( nCurves.eq.1 ).and.isatt( i_res, "gsnYRefLine" ) ) then
Carl Schreck's avatar
Carl Schreck committed
72
73
74
75
76
;   res@gsnBelowYRefLineColor := (/ "blue", "transparent" /)
;   res@gsnAboveYRefLineColor := (/ "transparent", "red" /)
;   res@gsnYRefLine := (/ -1, 1 /)
    res@gsnBelowYRefLineColor := "blue"
    res@gsnAboveYRefLineColor := "red"
77
  else
78
    res@xyMonoDashPattern   := .not.isatt( i_res, "xyDashPatterns" )
79
    res@xyLineColors        := (/ "indianred1", "skyblue3", "orchid4", "tan1", \
80
81
82
83
84
85
86
87
88
89
90
        "pink1", "darkslategray3", "thistle3", "khaki3" /)
    if( isatt( i_res, "xyColorMap" ) \
        .and.( str_lower(i_res@xyColorMap).eq."bold" ) ) then
      res@xyLineColors     := (/ "red", "blue", "purple", "orange",  \
          "magenta", "cyan", "seagreen", "brown" /)
    end if
    if( isatt( i_res, "xyColorMap" ) \
        .and.( str_lower(i_res@xyColorMap).eq."nca" ) ) then
      res@xyLineColors     := (/ "steelblue", "chocolate2", "chartreuse4", \
          "lightgoldenrod1", "purple4", "firebrick" /)
    end if
91
92
93
94
95
    if( isatt( i_res, "xyLineColors" ) ) then
      res@xyMarkerColors      := i_res@xyLineColors
    else
      res@xyMarkerColors      := res@xyLineColors
    end if
96
    res@xyMarkers           := (/  16,   6,  2,  5,  7,  8,  9, 12 /)
97
98
99
100
    res@xyMarkerThicknessF := 2
    res@xyLineThicknessF   := 2
;   res@xyMarkerThicknesses := (/   1,   1,  1,  1,  1,  1,  1,  1 /) * 2
;   res@xyLineThicknesses   := (/   1,   1,  1,  1,  1,  1,  1,  1 /) * 2
101
    res@xyMarkerSizes       := (/   1, 1,  1,  1,  1,  1,  1,  1 /) * 0.007
102
103
104
105
106
   
  end if

  if( i_res ) then
    copy_VarAtts( i_res, res )
107
  end if
Carl Schreck's avatar
Carl Schreck committed
108
  delete(res@fontHeightF)
109
110
  if( isatt( res, "xyColorMap" ) ) then
    delete(res@xyColorMap)
111
  end if
112
  if( isatt( i_res, "xyExplicitLabels" ) ) then
113
;   res@xyExplicitLabels       := " " + i_res@xyExplicitLabels
114
  end if
115
116
117
118

  print_clock( "Drawing the plot" )

  retVal = gsn_csm_xy( io_wks, i_xData, i_yData, res )
119
120
121
122
123
124
125
126
127
128
129
130
131
132

  if( isatt( i_res, "xyExplicitLabels" ) \
      .or.( ( isatt(i_res, "pmLegendDisplayMode") ) \
      .and.( i_res@pmLegendDisplayMode.eq."Always" ) ) ) then

    ; ...set up the legend
    genRes = True
    genRes@simple = True
    genRes = pick_legend_corner( i_xData, i_yData, genRes )


    lineRes = True
    lineRes@lgLineColors = res@xyLineColors(:nCurves-1)
    lineRes@lgLineThicknesses = res@xyLineThicknessF
133
134
135
136
    if( .not.res@xyMonoDashPattern ) then
      lineRes@lgMonoDashIndex = True
      lineRes@lgDashIndexes = res@xyDashPatterns
    end if
137
138
139
140
141
142
143
144
145

    textRes = True
    textRes@lgLabels = res@xyExplicitLabels
    textRes@lgLabelFontHeights     := res@gsnLeftStringFontHeightF * 0.75

    retVal = simple_legend( io_wks, retVal, genRes, lineRes, textRes )
  end if


146
147
148
  return(retVal)
end; cjs_draw_xy