You are here: Home / Services / Data Analysis and Visualization / Visualization / Software / NCL / PyNGL / DKRZ PyNGL example colored Hovmueller plot

DKRZ PyNGL example colored Hovmueller plot

The following example shows how to create a color filled Hovmueller plot.

Example:

from __future__ import print_function
import numpy as np
import os, sys
import Ngl,Nio

#-- data path and file name
ncarg_root = os.environ.get('NCARG_ROOT')
diri  = ncarg_root + '/lib/ncarg/data/cdf/'
fname = 'chi200_ud_smooth.nc'

#-- open file and read variables
f     =  Nio.open_file(diri + fname,"r")    #-- open data file
chi   =  f.variables['CHI'][:,:]            #-- read variable CHI[time,lon]
lon   =  f.variables['lon'][:]
time  =  f.variables['time'][:]

scale =  1.0e6
chi   =  chi/scale

#-- create the plot
wks =  Ngl.open_wks('png','plot_hovmueller_5')
                                            #-- open workstation
#-- set resources
res                       =  Ngl.Resources
res.nglFrame              =  False
res.nglMaximize           =  True           #-- maximize plot output

res.tiMainString          = 'Default Hovmu~H-13V2F35~H~FV-2H3~ller' #-- title

res.cnFillOn              =  True           #-- turn on color fill
res.cnFillPalette         = "BlWhRe"        #-- set color map
res.cnLineLabelsOn        =  False
res.cnLevelSelectionMode  = "ManualLevels"  #-- manual contour levels
res.cnMinLevelValF        = -10.            #-- min level
res.cnMaxLevelValF        =  10.            #-- max level
res.cnLevelSpacingF       =   2.            #-- contour level spacing

res.lbOrientation         = "horizontal"    #-- horizontal labelbar

res.sfXArray              =  lon[100:220]   #-- scalar field x
res.sfYArray              =  time           #-- scalar field y
 
res.tiYAxisString         = 'elapsed time'
res.tmYLLabelFontHeightF  =  0.015

res.nglPointTickmarksOutward = True         #-- point tickmarks out

plot = Ngl.contour(wks,chi[:,100:220],res)             #-- draw contours

#-- advance the frame
Ngl.frame(wks)

#-- end
Ngl.end()

Result:

DKRZ NCL example colored Hovmueller plot w400

Document Actions