Making certain values a certain color

From: Ertl, John <john.ertl_at_nyahnyahspammersnyahnyah>
Date: Tue, 15 Mar 2005 13:50:40 -0800

All,

I thought I had this figured out but now I have no idea what is going on. I
bet I need to set something else but I am not sure what.

I have an RH field and I want to be able to have certain rh values have a
specific color. This is easy if there is always the full range of 0-100%
but if the lower values are missing then the scale gets messed up. I have
tried to set the max, min and spacing and then using cnFillColors but it
looks to be ignoring the colors I have chosen.

Below is the code...This particular test was just supposed to alternate two
colors...did not work. I get a fill but it looks to be just stating at the
bottom of the color table and moving up the table with each layer. The end
goal is to be able to highlight certain RH value ranges by using a specific
color.

Thanks.

import Ngl
import Numeric

rhisobar = Numeric.array( \
[ \
  [ 0, 0, 0, 0, 0, \
    0, 0, 0, 0, 0, \
    0, 0, 0, 0, 0, \
    0, 0, 0, 0, 0, \
    0, 0, 0, 0, 0 \
  ], \
  [ 20, 20, 20, 20, 20, \
    20, 20, 20, 20, 20, \
    20, 20, 20, 20, 20, \
    20, 20, 20, 20, 20, \
    20, 20, 20, 20, 20 \
  ], \
  [ 40, 40, 40, 40, 40, \
    40, 40, 40, 40, 40, \
    40, 40, 40, 40, 40, \
    40, 40, 40, 40, 40, \
    40, 40, 40, 40, 40 \
  ], \
  [ 50, 50, 50, 50, 50, \
    50, 50, 50, 50, 50, \
    50, 50, 50, 50, 50, \
    50, 50, 50, 50, 50, \
    50, 50, 50, 50, 50 \
  ], \
  [ 60, 60, 60, 60, 60, \
    60, 60, 60, 60, 60, \
    60, 60, 60, 60, 60, \
    60, 60, 60, 60, 60, \
    60, 60, 60, 60, 60 \
  ], \
  [ 70, 70, 70, 70, 70, \
    70, 70, 70, 70, 70, \
    70, 70, 70, 70, 70, \
    70, 70, 70, 70, 70, \
    70, 70, 70, 70, 70 \
  ], \
  [ 80, 80, 80, 80, 80, \
    80, 80, 80, 80, 80, \
    80, 80, 80, 80, 80, \
    80, 80, 80, 80, 80, \
    80, 80, 80, 80, 80 \
  ], \
  [ 90, 90, 90, 90, 90, \
    90, 90, 90, 90, 90, \
    90, 90, 90, 90, 90, \
    90, 90, 90, 90, 90, \
    90, 90, 90, 90, 90 \
  ],
## [ 100, 100, 100, 100, 100, \
## 100, 100, 100, 100, 100, \
## 100, 100,100,100, 100, \
## 100,100, 100, 100, 100, \
## 100,100,100,100,100 \
## ] \
], Numeric.Float0)
levels = [ 1000., 975., 950., 925., 850., 700., 500., 400.]

taus = Numeric.array([ \
         0., 3., 6., 9., 12., \
        15., 18., 21., 24., 27., \
        30., 33., 36., 39., 42., \
        45., 48., 51., 54., 57., \
        60., 63., 66., 69., 72. \
       ],Numeric.Float0)

colors = Numeric.array([
  [255,255,255],[0,0,0],
  [0,255,255],
  [255,0,0],
  [0,255,0],
  [0,0,255],
  [220,255,220],
  [190,255,190],
  [120,255,120],
  [80,255,80],
  [50,200,50],
  [20,150,20],
  [0,0,255],
  [255,0,0],
  [160,160,160]]) /255.0

rlist = Ngl.Resources()
rlist.wkColorMap = colors
wks = Ngl.open_wks('x11','plotname',rlist)

#
rh_res = Ngl.Resources()

rh_res.trYReverse = True # Reverse the Y values.
rh_res.nglDraw = False # Don't draw individual plot.
rh_res.nglFrame = False # Don't advance frame.
rh_res.vpXF = 0.15 # x location
rh_res.vpYF = 0.90 # y location
rh_res.vpWidthF = 0.7 # width
rh_res.vpHeightF = 0.30 # height
rh_res.tmXBLabelJust = "CenterCenter"
rh_res.cnInfoLabelOn = False # turn off cn info label. Gives warnings
rh_res.sfXArray = taus # Define X/Y axes values. Gives warnings
rh_res.sfYArray = levels # all three data fields. Gives warnings
rh_res.nglMaximize = False # need to be set otherwise vp stuff is
not used
rh_res.pmLabelBarDisplayMode = "Never"
rh_res.sfMissingValueV = 999.0

rh_res.tiYAxisFontHeightF = .009
rh_res.tiYAxisString = "Temp(F) RH Wind(kt):C: millibars" # Y
axes label.
rh_res.tiMainString = "Meteogram for Test Z"

rh_res.tmYLMode = "Explicit" # Define own tick mark labels.
rh_res.tmYLLabelFont = 25 # Change the font.
rh_res.tmYLValues = levels
rh_res.tmYLLabels = levels
#["1000","975","950","925","850","800","700","600","500", "400"]
rh_res.tmYLMinorOn = False # No minor tick marks.

rh_res.tmXBMajorOutwardLengthF = .01 # makes bottom tick marks face
outward
rh_res.tmXBMode = "Explicit" # Define own tick mark labels.
rh_res.tmXBLabelFont = 25 # Change the font.
rh_res.tmXBValues = taus
rh_res.tmXBLabelFontHeightF = .018 # Font size
rh_res.tmYLLabelFontHeightF = .014 # Font size
rh_res.tmXBLabels = taus #[tauLabel] # insert a list
rh_res.tmXBLabelAngleF = 90. # change label angle
rh_res.tmXBMinorOn = False # No minor tick marks.

rh_res.cnLevelSelectionMode = "ManualLevels"
rh_res.cnMinLevelValF = 0.0
rh_res.cnMaxLevelValF = 100.0
rh_res.cnLevelSpacingF = 10.0

rh_res.cnFillColors = [3,4,3,4,3,4,3,4,3,4,3] #should alternate
colors doe not work

rh_res.cnLineLabelsOn = True # contour labels
rh_res.cnFillOn = True # turns on the color

rhfill = Ngl.contour(wks,rhisobar,rh_res)

Ngl.draw(rhfill)
Ngl.frame(wks)

John C. Ertl
Fleet Numerical Meteorology & Oceanography Center
7 Grace Hopper Ave
Monterey, CA 93943
phone: (831) 656-5704
fax: (831) 656-4363

_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Tue Mar 15 2005 - 14:50:40 MST

This archive was generated by hypermail 2.2.0 : Thu Jan 19 2006 - 21:31:53 MST