|
Contour plot
Set up
- Many of the functions and routines used for plotting are in the files called "gsn_code.ncl", "gsn_csm.ncl", "shea_util.ncl" and "contributed.ncl", which come along with the instalation of NCL. To use plotting functions one needs to first load these files.
; load necessary ncl files:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
- To plot data, one first has to open a workstation where the plot will be framed. Workstation can be a frame on screen (x11) or a file (eps and epsi for one page, and ps and pdf for multiple pages). However, here we'll be working only with the x11 (screen).
; open workstation
wks = gsn_open_wks("x11","contour-plot")
- Plots can be made from data stored in files, or from calculated variables. For simplicity, here we use data stored in the file. NCL supports various formats of data. Here, we only provide examples of NetCDF format.
; open the file to read data from it
fi2 = addfile("21600.g9.dws.nc","r")
; read in data
; 1. coordinates
t = fi2->t
x = fi2->x
y = fi2->y
; 2. data
w200 = fi2->w_200
Contour line plot
- Plotting can be quick with NCL automaticly choosing the settings:
; original contour line plot
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),False)
- One can customize the plots to the publishing quality without too much effort, but lots of patience:
; customize plot by setting the resources
res = True
- Change the axes
res@tiMainString = "Axes titles and labels"
res@tiXAxisString = "x [km]"
res@tiYAxisString = "y [km]"
res@sfXArray = x/1.e3
res@sfYArray = y/1.e3
- Explicitly choose contours
res@tiMainString = "Explicitly choose contours"
res@cnLevelSelectionMode = "ExplicitLevels"
res@cnLevels = (/-1.2,-.6,0.,.6,1.2/)
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
- Mark the contours according to the sign
- hange the pattern and the thicknes of the contours
res@tiMainString = "Introduce dashed pattern for negative values and thicker zero line"
res@gsnContourNegLineDashPattern = 1
res@gsnContourZeroLineThicknessF = 2.
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
- Change the color of contours
res@tiMainString = "Color the contours according to their sign"
res@gsnDraw = False
res@gsnFrame = False
res@cnLineLabelsOn = False
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
plot = ColorNegDashZeroPosContour(plot,"red","magenta","blue")
draw(wks)
frame(wks)
- Emphasize extreemes
res@tiMainString = "Shade areas where field values exceed given range"
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
plot = ColorShadeLeGeContour(plot,-0.6,"salmon",0.6,"cyan")
draw(wks)
frame(wks)
Filled contour plot
- Prepare workstation to use color table instead of named colors
; define color table
gsn_define_colormap(wks,"nrl_sirkes")
- Set axes the way we have had them
res = True
res@gsnMaximize = True
res@sfXArray = x/1.e3
res@sfYArray = y/1.e3
res@tiXAxisString = "x [km]"
res@tiYAxisString = "y [km]"
- Turn off contour lines and turn on fill in mode
res@tiMainString = "Instead of contour lines have filled contour plot"
res@cnLevelSelectionMode = "AutomaticLevels"
res@cnFillOn = True
res@cnRasterModeOn = True
res@cnLinesOn = False
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
- Restrict the contour spread
res@tiMainString = "Restrict the contour spread"
res@cnLevelSelectionMode = "ManualLevels"
res@cnMinLevelValF = -1.5
res@cnMaxLevelValF = 1.5
res@cnLevelSpacingF = .3
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
- Restrict the color spread
res@tiMainString = "Restrict the color spread"
res@gsnSpreadColors = True
res@gsnSpreadColorStart = 2
res@gsnSpreadColorEnd = 22
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
- Orient color bar vertically
res@tiMainString = "Orient color bar vertically"
res@lbOrientation = "vertical"
plot = gsn_csm_contour(wks,w200(dimsizes(t)-1,:,:),res)
|
|