DKRZ NCL font and function code example#

Example script:

;----------------------------------------------------------------------
;-- DKRZ NCL example:     NCL_font_and_function_codes.ncl
;--
;-- Description:          show text function codes
;--                       - set font color
;--                       - set font via @txFont or via ~Fxx~ in text string
;--                       - decrease/increase font size
;--                       - increase font thickness
;--                       - superscript and subscript
;--                       - vertical justification
;--                       - German Umlaute
;--
;-- 30.06.14  kmf
;----------------------------------------------------------------------
begin
;-- open a workstation
  wks_type          = "png"
  wks_type@wkWidth  =  1024
  wks_type@wkHeight =  1024
  wks  = gsn_open_wks(wks_type, "plot_function_codes")  ;-- open a workstation

;-- set plot resources
  ndcres  =  True     ;-- open a kind of container to store all plot settings
  ndcres@gsnDraw          =  False             ;-- don't advance frame
  ndcres@gsnFrame         =  False             ;-- don't advance frame

  ndcres@txFontHeightF    =  0.03              ;-- decrease font size
  ndcres@txJust           = "CenterCenter"     ;-- text justification
  ndcres@txFont           = "helvetica-bold"   ;-- change font

  txid = gsn_create_text_ndc(wks,"Fonts and Function Codes", 0.5,0.96,ndcres)

  ndcres@txFontHeightF    =  0.03              ;-- decrease font size
  ndcres@txJust           = "BottomLeft"       ;-- text justification
  ndcres@txFont           = "helvetica"        ;-- change font

  line1 = "Font Height = 0.03"
  gsn_text_ndc(wks, line1, 0.09, 0.86, ndcres)

  line2 = "Font Height = 0.015"
  ndcres@txFontHeightF    =  0.015             ;-- decrease font size
  gsn_text_ndc(wks, line2, 0.09, 0.83, ndcres)

  line3 = "Font Height = 0.01"
  ndcres@txFontHeightF    =  0.01              ;-- decrease font size
  gsn_text_ndc(wks, line3, 0.09, 0.80, ndcres)

;-- superscripting
  ndcres@txFontHeightF    =  0.03              ;-- make font size smaller
  ndcres@txFontColor      = "blue"             ;-- change to white
  ndcres@txJust           = "BottomLeft"       ;-- text justification

  super = "Superscripting:  35.5~S~o~N~   x~S~2~N~   kgm~S~-2~N~s~S~-1~N~"
  gsn_text_ndc(wks, super, 0.09, 0.74, ndcres)

;-- subscripting
  sub   = "Subscripting:     H~B~2~N~O   CO~B~2~N~"
  gsn_text_ndc(wks, sub,   0.09, 0.69, ndcres)

;-- different font size in one string
  str_one = "Different ~Z70~font ~Z130~sizes~Z100~ in one ~Z60~string~Z100~"
  ndcres@txFontColor      = "seagreen"         ;-- change to white
  gsn_text_ndc(wks, str_one, 0.09, 0.63, ndcres)

;-- Umlaute
  Auml  = "A~H-15V6F35~H~FV-6H3~"
  auml  = "a~H-13V2F35~H~FV-2H3~"
  Ouml  = "O~H-16V6F35~H~FV-6H3~"
  ouml  = "o~H-14V2F35~H~FV-2H3~"
  Uuml  = "U~H-15V6F35~H~FV-6H3~"
  uuml  = "u~H-13V2F35~H~FV-2H3~"
  str   = "Umlaute:    "+Auml+" "+auml+"   "+Ouml+" "+ouml+"   "+Uuml+" "+uuml

  ndcres@txFontColor      = "black"            ;-- change to white
  ndcres@txFontHeightF    =  0.025             ;-- make font size smaller
  gsn_text_ndc(wks, str, 0.09, 0.57, ndcres)

;-- total 43 fonts available in v6.2.0

  str_abc   = "abcdefghijklmnopqrstuvwxyz"

;-- helvetica-bold
  ndcres@txFont           = "helvetica-bold"   ;-- change font
  ndcres@txFontColor      = "red"              ;-- change to white
  gsn_text_ndc(wks, "Font examples (43 fonts available in NCL)", 0.09, 0.50, ndcres)

;-- default: helvetica
  ndcres@txFontColor      = "black"            ;-- change to white
  ndcres@txFont           = "helvetica"        ;-- change font
  gsn_text_ndc(wks, "helvectica :      "+str_abc, 0.09, 0.45, ndcres)

;-- times-roman
;  ndcres@txFont           = "times-roman"     ;-- change font
  gsn_text_ndc(wks, "~F21~times-roman :  ~F25~"+str_abc, 0.09, 0.40, ndcres)

;-- times-bold
;  ndcres@txFont           = "times-bold"      ;-- change font
  gsn_text_ndc(wks, "~F21~times-bold :     ~F26~"+str_abc, 0.09, 0.35, ndcres)

;-- courier
;  ndcres@txFont           = "courier"         ;-- change font
  gsn_text_ndc(wks, "~F21~courier :          ~F29~"+str_abc, 0.09, 0.30, ndcres)

;-- courier-bold
;  ndcres@txFont           = "courier-bold"    ;-- change font
  gsn_text_ndc(wks, "~F21~courier-bold :  ~F30~"+str_abc, 0.09, 0.25, ndcres)

;-- greek
;  ndcres@txFont           = "greek"           ;-- change font
  gsn_text_ndc(wks, "~F21~greek :            ~F33~"+str_abc, 0.09, 0.20, ndcres)

;-- math-symbols
  ndcres@txFontThicknessF =  2.0
;  ndcres@txFont           = "math-symbols"    ;-- change font
  gsn_text_ndc(wks, "~F21~math-symbols : ~F34~aeqrstu1234567890!$%&/()", 0.09, 0.15, ndcres)

;-- weather2
;  ndcres@txFont           = "weather2"        ;-- change font
  gsn_text_ndc(wks, "~F21~weather2 :       ~F37~"+str_abc, 0.09, 0.10, ndcres)

;-- text-symbols
  str_abc = "bcdklmnopqrstuxyz236-+;"
;  ndcres@txFont           = "text-symbols"    ;-- change font
  gsn_text_ndc(wks, "~F21~text-symbols :  ~F35~"+str_abc, 0.09, 0.05, ndcres)

;-- across / down
  down   = "write downward"
  ndcres@txFontThicknessF =  1.0               ;-- default: 1.0
  ndcres@txFontColor      = "seagreen"         ;-- change to white
  ndcres@txJust           = "CenterCenter"     ;-- text justification
  gsn_text_ndc(wks, "~F21D~"+down,   0.03, 0.3, ndcres)

;-- create the plot
  draw(txid)
  frame(wks)
end

Result:

../../../../../../_images/plot_function_codes_w400.png