-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTRANS_contour_fill.py
80 lines (67 loc) · 2.05 KB
/
TRANS_contour_fill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
# 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()