Sie sind hier: Startseite / Services / Data Analysis and Visualization / Visualization / Software / NCL / examples / source_code / DKRZ NCL Workshop: xy-plots
Info
Alle Inhalte des Nutzerportal sind nur auf Englisch verfügbar.

DKRZ NCL Workshop: xy-plots

All xy-plots from the DKRZ NCL Workshop. Requirement: NCL version 6.2.0 and higher

 

1. Simple xy-plot:

 begin

  ;-- generate data
   x = ispan(-20,20,1)
   y = random_uniform(-5,5,dimsizes(x))

  ;-- open a workstation (assign graphic output file 'part_I_simple_xy.png')
   wks = gsn_open_wks("png", "part_I_simple_xy")

  ;-- create the plot
   plot = gsn_csm_xy(wks, x, y, False)

end

 

2. Read and plot ASCII data from file:

begin

;-- read ASCII data
   data_col = asciiread("$NCL_TUT/data/ASCII_data.asc", (/12,2/), "integer") ;-- formatted read

   printVarSummary(data_col)                ;-- print 

   x = data_col(:,0)                        ;-- get all data from column 1
   y = data_col(:,1)                        ;-- get all data from column 2

;-- open a workstation
   wks = gsn_open_wks("x11", "part_I_read_ASCII_data_xy")

;-- set resources
   res               =  True                ;-- create plot resource object
   res@tiMainString  = "counts per day"     ;-- draw a title on top of the plot

;-- create the plot
   plot = gsn_csm_xy(wks, x, y, res)

end 

 

3. Read data from netCDF file and create a xy-plot using geographical data:

begin

;-- open a data file
   f = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

;-- set variables
   x = f->u&lat                            ;-- x-axis is latitude
   y = f->u(0,0,:,{45})                    ;-- values at longitude 10 deg.

;-- open a workstation
   wks = gsn_open_wks("png", "part_I_read_data_xy")

;-- set resources
   res               =  True                ;-- create plot resource object
   res@tiMainString  = "Title:  zonal wind" ;-- draw a title on top of the plot

;-- create the plot
   plot = gsn_csm_xy(wks, x, y, res)

end

 

4. Plot multiple curves:

begin

;-- open a data file
   f = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

;-- set variable (zonal wind)
   u = f->u                                ;-- set variable u

   data      = new((/2,dimsizes(u&lat)/), float)  ;-- assign multidimensional array
   data(0,:) = u(0,0,:,{10})               ;-- values at longitude 10 deg.
   data(1,:) = u(0,0,:,{-105})             ;-- values at longitude -105 deg.

;-- open a workstation
   wks = gsn_open_wks("png", "part_I_multiple_curves_xy")

;-- set resources
   res               =  True                ;-- create plot resource object
   res@xyLineColors  = (/"blue", "red"/)    ;-- line colors
   res@xyLineThicknesses = (/2.0,2.0/)      ;-- set line thickness
   res@tiMainString  = "Zonal winds at lon 10 deg (blue) and -105 deg (red)" ;-- draw title

;-- create the plot
   plot = gsn_csm_xy(wks, u&lat, data, res)

end   

 

5. Change dash pattern:

begin

  ;-- open a data file
   f = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

  ;-- set variable (zonal wind)
   u = f->u                                ;-- set variable u

   data      = new((/3,dimsizes(u&lat)/), float)  ;-- assign multidimensional array
   data(0,:) = u(0,0,:,{10})               ;-- values at longitude 10 deg.
   data(1,:) = u(0,0,:,{-105})             ;-- values at longitude -105 deg.
   data(2,:) = u(0,0,:,{-120})             ;-- values at longitude -120 deg.

  ;-- open a workstation
   wks = gsn_open_wks("png", "part_I_dash_pattern_xy")

  ;-- set resources
   res               =  True                ;-- create plot resource object
   res@xyLineColors  = (/"blue", "red", "green4"/) ;-- line colors
   res@xyLineThicknesses = (/2.0, 3.0, 3.0/)  ;-- set line thickness
   res@xyDashPatterns    = (/0, 11, 4/)       ;-- 0=solid, 11=dashed, 2=dotted
   res@tiMainString  = "Zonal winds at lon 10 (blue), -105 (red) and -120 (green) deg" ;-- draw title

  ;-- create the plot
   plot = gsn_csm_xy(wks, u&lat, data, res)

end

 

 6. Color fill between two curves:

begin

  ;-- open a data file
   f = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

  ;-- set variable (zonal wind)
   u = f->u                                ;-- set variable u

   data      = new((/2,dimsizes(u&lat)/), float)  ;-- assign multidimensional array
   data(0,:) = u(0,0,:,{10})               ;-- values at longitude 10 deg.
   data(1,:) = u(0,0,:,{-105})             ;-- values at longitude -105 deg.

  ;-- open a workstation
   wks = gsn_open_wks("png", "part_I_fill_between_lines_xy")

  ;-- set resources
   res                       =  True       ;-- create plot resource object
   res@xyLineThicknessF      =  2.0        ;-- set line thickness

   res@gsnXYAboveFillColors  = "red"       ;-- fill with red above the reference line
   res@gsnXYBelowFillColors  = "blue"      ;-- fill with blue below the reference line

   res@tiMainString  = "Zonal winds at lon 10 (blue) and -105 (red) deg" ;-- draw title

  ;-- create the plot
   plot = gsn_csm_xy(wks, u&lat, data, res)

end 

 

 7. Color fill above and below a reference line:

begin

   x = fspan(1., 12.,24)                         ;-- generate x values
   y = random_uniform(-1.,1.,24)                 ;-- generate y values

   wks = gsn_open_wks("png","part_I_colored_above_below_xy") ;-- open workstation

   res                       =  True             ;-- create plotting resource object
   res@tmXBMode              = "Explicit"        ;-- use explicit labels
   res@tmXBValues            =  x                ;-- set x-axis values
   res@tmXBLabelFontHeightF  =  0.015            ;-- x-axis label font size
   res@tmXBLabels            =  (/"Jan","","Feb","","Mar","","Apr","","May","","Jun","",\
                                  "Jul","","Aug","","Sep","","Oct","","Nov","","Dec",""/)

   res@gsnYRefLine           =  0.               ;-- reference line at 0. 
   res@gsnAboveYRefLineColor = "red"             ;-- fill with red above the reference line
   res@gsnBelowYRefLineColor = "blue"            ;-- fill with blue below the reference line

   res@tiMainString          = "XY-Plot: coloring above/below reference line"  ;-- draw title

   plot = gsn_csm_xy(wks,x,y,res)                ;-- create the plot

end

 

8. Plot auxiliary grid lines:

begin

;-- open a data file
   f = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

;-- set variable (zonal wind)
   u = f->u                                ;-- set variable u

   data      = new((/2,dimsizes(u&lat)/), float)  ;-- assign multidimensional array
   data(0,:) = u(0,0,:,{10})               ;-- values at longitude 10 deg.
   data(1,:) = u(0,0,:,{-105})             ;-- values at longitude -105 deg.

;-- open a workstation
   wks = gsn_open_wks("png", "part_I_auxiliary_grid_lines_xy")

;-- set resources
   res                             =  True     ;-- create plot resource object
   res@xyLineColors                = (/"blue", "red"/)  ;-- line colors
   res@xyLineThicknessF            =  2.0      ;-- set line thickness

   res@tmXMajorGrid                =  True     ;-- turn on x-grid
   res@tmXMajorGridThicknessF      =  1.0      ;-- thinner the lines
   res@tmXMajorGridLineDashPattern =  2        ;-- use dashed lines
  
   res@tmYMajorGrid                =  True     ;-- turn on y-grid
   res@tmYMajorGridThicknessF      =  1.0      ;-- thinner the lines
   res@tmYMajorGridLineDashPattern =  2        ;-- use dashed lines

   res@tiMainString  = "Zonal winds at lon 10 (blue) and -105 (red) deg" ;-- draw title

;-- create the plot
   plot = gsn_csm_xy(wks, u&lat, data, res)

end 

 

9. XY-plot with two different y-axis:

begin

;-- open a data file
   f   = addfile("$NCL_TUT/data/EH_OM_A1B_3Dvectors_t1-24.nc","r")

;-- set variable (zonal wind)
   t   = f->t(0,0,:,{10})     ;-- set variable t;    y-axis on the left
   slp = f->slp(0,:,{10})     ;-- set variable slp;  y-axis on the right
   x   = f->lat
 
;-- open a workstation
   wks = gsn_open_wks("png", "part_I_two_different_y_axis_xy")

;-- resources for variable left y-axis
   resT                      =  True
   resT@xyLineThicknessF     =  3.0                            ;-- set line thickness
   resT@xyLineColor          = "red"                           ;-- set line color
   resT@xyDashPatterns       =  0                              ;-- solid line
   resT@tiYAxisString        = t@long_name +"  "+"[solid]"     ;-- axis string

;-- resources for variable right y-axis
   resSLP                    =  True      
   resSLP@xyLineThicknessF   =  3.0                            ;-- set line thickness    
   resSLP@xyLineColor        = "blue"                          ;-- set line color            
   resSLP@xyDashPatterns     =  1                              ;-- dashed line
   resSLP@tiYAxisString      =  slp@long_name +"  "+"[dash]"   ;-- axis string
   resSLP@tiMainString  = "Temperature and Sea Level Pressure at lon=10 deg" ;-- draw title

;-- create the plot
   plot = gsn_csm_xy2(wks, x, t, slp, resT, resSLP)

end 

 

Artikelaktionen