#
#  File:
#    TRANS_contour_fill.py
#
#  Synopsis:
#    Illustrates how to create a contour fill plot
#
#  Categories:
#    contour plot
#
#  Author:
#    Karin Meier-Fleischer, based on NCL example
#  
#  Date of initial publication:
#    September 2018
#
#  Description:
#    This example shows how to create a contour fill plot.
#
#  Effects illustrated:
#    o  Drawing a contour fill plot
# 
#  Output:
#    A single visualization is produced.
#
#  Notes: The data for this example can be downloaded from 
#    http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/
#    
'''
  Transition Guide Python Example: 	TRANS_contour_fill.py

  - contour fill plot

  18-09-03  kmf
'''
import numpy as np
import Ngl
import os

#-- create some dummy data to contour
T    = np.zeros((25,25),np.float32)
jspn = np.power(np.arange(-12,13),2)
ispn = np.power(np.arange(-12,13),2)

for i in range(0,len(ispn)):
	T[i,:] = (jspn + ispn[i]).astype(np.float32)

T = 100.0 - np.sqrt(64 * T)

#-- start the graphics
wks = Ngl.open_wks("png",os.path.basename(__file__).split('.')[0])

#-- resource settings
res                    =  Ngl.Resources()
res.nglDraw            =  False           #-- don't draw plot
res.nglFrame           =  False           #-- don't advance the frame
res.nglPointTickmarksOutward = True       #-- point tickmarks outward

res.cnFillOn           =  True            #-- turn on contour level fill
res.cnLineLabelsOn     =  False           #-- turn off contour line labels
res.cnFillPalette      = "ncl_default"

res.lbLabelPosition    = "Center"
res.lbLabelFontHeightF =  0.018           #-- make labelbar labels smaller
res.lbLabelAlignment   = "BoxCenters"
res.lbLabelStrings     =  list(range(-30,110,10)) #-- doesn't appear to work

#-- create the contour plot
plot = Ngl.contour(wks,T,res)

#-- bug work-around (v1.5.2): apply the labels after the plot has been created
nrlist                   =  Ngl.Resources()
nrlist.lbLabelStrings    =  list(range(-30,110,10))
Ngl.set_values(plot,nrlist)

#-- draw the plot and advance the frame
Ngl.draw(plot)
Ngl.frame(wks)

Ngl.end()
