Personal tools

##### Sektionen
You are here: Home / Beispiele und Aufgaben Teil III - Vektoren
Info
Our docs have moved to https://docs.dkrz.de This portal will be shutdown as soon the last content is migrated.

# Beispiele und Aufgaben Teil III - Vektoren

NCL Skripte zur Erzeugung von Vektor Plots.

Einfacher Vektor Plot:

```begin

u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
wks =  gsn_open_wks("png","part_III_simple_vectors")

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

;-- create the plot
plot = gsn_csm_vector_map(wks,u,v,res)

end```

Vektoreigenschaften definieren:

```begin

u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
wks =  gsn_open_wks("png","part_III_vector_settings")

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

res@vcRefMagnitudeF  =  5.            ;-- make vectors larger
res@vcRefLengthF     =  0.02          ;-- ref vec length
res@vcMinDistanceF   =  0.01          ;-- thin out vectors

;-- create the plot
plot = gsn_csm_vector_map(wks,u,v,res)

;-- set vector style
res@vcGlyphStyle     = "CurlyVector"  ;-- turn on curly vectors

;-- create the second plot
plot = gsn_csm_vector_map(wks,u,v,res)

end```

Farbige Vektoren:

```begin

u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
wks =  gsn_open_wks("png","part_III_vector_colorize")

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

;-- vector resources
res@vcMinDistanceF            =  0.01             ;-- thin out vectors
res@vcGlyphStyle              = "CurlyVector"     ;-- turn on curly vectors
res@vcLineArrowColor          = "white"           ;-- change vector color to white
res@vcLineArrowThicknessF     =  2.0              ;-- change vector thickness
res@vcRefMagnitudeF           =  5.               ;-- make vectors larger
res@vcRefLengthF              =  0.025            ;-- ref vector length
res@vcRefAnnoArrowUseVecColor =  False            ;-- don't use vcLineArrowColor for ref
;   res@vcRefAnnoOrthogonalPosF   = -1.0             ;-- move ref vector upper right edge

;-- map resources
res@mpOutlineOn               =  True             ;-- draw coastlines
res@mpLandFillColor           = "AntiqueWhite2"   ;-- fill land areas with color
res@mpOceanFillColor          = "lightblue"       ;-- fill ocean areas with color
res@mpInlandWaterFillColor    = "lightblue"       ;-- fill inland water areas with color

;-- create the plot
plot = gsn_csm_vector_map(wks,u,v,res)

end```

Vektoren koloriert mithilfe einer Variablen:

```begin

u =  f->u10(0,:,:)            ;-- u-velocity, first time step
v =  f->v10(0,:,:)            ;-- v-velocity, first time step
t =  f->tsurf(0,:,:)          ;-- surface temperature

;-- define the workstation (graphic will be written to a file)
wks =  gsn_open_wks("png","part_III_vector_colorize_temp")

;-- set resources
res                           =  True             ;-- create plot resource object
res@tiMainString              = "Vector plot colorized by surface temperature" ;-- draw a title

;-- vector resources
res@vcGlyphStyle              = "CurlyVector"     ;-- turn on curly vectors
res@vcLineArrowThicknessF     =  2.0              ;-- change vector thickness
res@vcRefAnnoArrowUseVecColor =  False            ;-- don't use vcLineArrowColor for ref
res@vcRefMagnitudeF           =  5.               ;-- make vectors larger
res@vcRefLengthF              =  0.025            ;-- ref vector length
res@vcMinDistanceF            =  0.01             ;-- thin out vectors

;-- map resources
res@mpOutlineOn               =  True             ;-- draw coastlines
res@mpLandFillColor           = "DarkGreen"       ;-- fill land areas with color
res@mpOceanFillColor          = "midnightblue"            ;-- fill ocean areas with color
res@mpInlandWaterFillColor    = "midnightblue"            ;-- fill inland water areas with color

res@lbBoxMinorExtentF         =  0.15             ;-- decrease the height of the labelbar
res@pmLabelBarOrthogonalPosF  = -0.2              ;-- move the labelbar up

;-- create the plot; using scalar variable t to colorize the vectors
plot = gsn_csm_vector_scalar_map(wks,u,v,t,res)

res@mpLandFillColor           = "AntiqueWhite2"   ;-- fill land areas with color
res@mpOceanFillColor          = "lightblue"       ;-- fill ocean areas with color
res@mpInlandWaterFillColor    = "lightblue"       ;-- fill inland water areas with color

;-- create a second plot, but use other colors for land and water
plot = gsn_csm_vector_scalar_map(wks,u,v,t,res)

end```

Vektoren über Kontur Plot gelegt:

```begin

u   =  f->u10(0,:,:)                         ;-- first time step
v   =  f->v10(0,:,:)                         ;-- first time step
t   =  f->tsurf(0,:,:)                       ;-- first time step

;-- define the workstation (graphic will be written to a file)

wks =  gsn_open_wks("png","part_III_vector_colorize_overlay")

;-- set plot resources
cnres                     =  True            ;-- contour resources
cnres@gsnDraw             =  False           ;-- don't draw plot, yet
cnres@gsnFrame            =  False           ;-- don't advance frame
cnres@gsnLeftString       =  t@long_name     ;-- change left string
cnres@gsnRightString      =  t@units         ;-- change right string

cnres@tiMainString        = "Overlay vectors on surface temperature contour plot"

cnres@cnFillOn            =  True            ;-- turn on fill colors
cnres@cnFillPalette       = "ncl_default"    ;-- choose colormap
cnres@cnLinesOn           =  False           ;-- don't draw contour lines

cnres@mpFillOn            =  False           ;-- turn off map fill

;-- set the vector resources
vcres                     =  True            ;-- vector resources
vcres@gsnDraw             =  False           ;-- don't draw vector plot, yet
vcres@gsnFrame            =  False           ;-- don't advance frame
vcres@gsnRightString      = " "              ;-- no right string
vcres@gsnLeftString       = " "              ;-- no left string
vcres@tiXAxisString       = " "              ;-- don't draw x-axis labels

vcres@vcGlyphStyle        = "CurlyVector"    ;-- use curly vectors
vcres@vcRefMagnitudeF     =  20              ;-- define vector reference magnitude
vcres@vcRefLengthF        =  0.045           ;-- define length of reference vector
vcres@vcRefAnnoOrthogonalPosF =  -1.36        ;-- move reference vector into plot
vcres@vcRefAnnoString2On  =  False

;-- create the plots, but don't draw them
cont_plot  = gsn_csm_contour_map(wks,t,cnres)
vec_plot   = gsn_csm_vector(wks,u,v,vcres)

;-- overlay vec_plot on cont_plot, but don't draw them
overlay(cont_plot, vec_plot)

;-- now, draw the plot and advance frame
draw(cont_plot)
frame(wks)

end```

## Für die Aufgabe:

part_III_Vector_colorize_overlay.ncl

```begin

u   =  f->u10(0,:,:)                         ;-- first time step
v   =  f->v10(0,:,:)                         ;-- first time step
t   =  f->tsurf(0,:,:)                       ;-- first time step

;-- define the workstation (graphic will be written to a file)

wks =  gsn_open_wks("png","part_III_vector_colorize_overlay")

;-- set plot resources
cnres                     =  True            ;-- contour resources
cnres@gsnDraw             =  False           ;-- don't draw plot, yet
cnres@gsnFrame            =  False           ;-- don't advance frame
cnres@gsnLeftString       =  t@long_name     ;-- change left string
cnres@gsnRightString      =  t@units         ;-- change right string

cnres@tiMainString        = "Overlay vectors on surface temperature contour plot"

cnres@cnFillOn            =  True            ;-- turn on fill colors
cnres@cnFillPalette       = "ncl_default"    ;-- choose colormap
cnres@cnLinesOn           =  False           ;-- don't draw contour lines

cnres@mpFillOn            =  False           ;-- turn off map fill

;-- set the vector resources
vcres                     =  True            ;-- vector resources
vcres@gsnDraw             =  False           ;-- don't draw vector plot, yet
vcres@gsnFrame            =  False           ;-- don't advance frame
vcres@gsnRightString      = " "              ;-- no right string
vcres@gsnLeftString       = " "              ;-- no left string
vcres@tiXAxisString       = " "              ;-- don't draw x-axis labels

vcres@vcGlyphStyle        = "CurlyVector"    ;-- use curly vectors
vcres@vcRefMagnitudeF     =  20              ;-- define vector reference magnitude
vcres@vcRefLengthF        =  0.045           ;-- define length of reference vector
vcres@vcRefAnnoOrthogonalPosF =  -1.36        ;-- move reference vector into plot
vcres@vcRefAnnoString2On  =  False

;-- create the plots, but don't draw them
cont_plot  = gsn_csm_contour_map(wks,t,cnres)
vec_plot   = gsn_csm_vector(wks,u,v,vcres)

;-- overlay vec_plot on cont_plot, but don't draw them
overlay(cont_plot, vec_plot)

;-- now, draw the plot and advance frame
draw(cont_plot)
frame(wks)

end```

Document Actions