[ncl-talk] annotated map on contour plot is transparent rather than white

Jatin Kala jatin.kala.jk at gmail.com
Mon Feb 22 02:56:59 MST 2016


Thanks Guido,
I don't know why, but it's not working in my script, the map is still 
transparent.
Modified script is attached.
Cheers,
Jatin

On 22/02/2016 5:13 PM, Guido Cioni wrote:
> Hi Jatin,
> did you try creating a new function that fill the background of an 
> annotated plot?
>
> function fill_background(wks,plot,color)
> local xmin,xmax,ymin,yma,gres,xbox,ybox
> begin
>   getvalues plot
>     "trXMinF"  : xmin
>     "trXMaxF"  : xmax
>     "trYMinF"  : ymin
>     "trYMaxF"  : ymax
>   end getvalues
>
>   xbox = (/xmin,xmax,xmax,xmin,xmin/)
>   ybox = (/ymin,ymin,ymax,ymax,ymin/)
>
> ;---Resources for filling the polygon
>   gres = True
>   gres at gsFillColor = color
>   gres at tfPolyDrawOrder = "PreDraw"    ; This is necessary so that the
>                 ; fill doesn't cover the curves.
>
> ;---Attach polygon to existing plot and return
>   dum = gsn_add_polygon(wks,plot,xbox,ybox,gres)
>   return(dum)
> end
>
> Attached you find an example of an application with pdf and NCL source 
> file used to generate the plot.
> Hope this helps.
>
> Cheers
>
>
>
>
>
>
> Guido Cioni
> http://guidocioni.altervista.org
>
>> On 22 Feb 2016, at 06:51, Jatin Kala <jatin.kala.jk at gmail.com 
>> <mailto:jatin.kala.jk at gmail.com>> wrote:
>>
>> Hi,
>> I am annotating a map on top of a contour plot. However, the map is 
>> being plotted as transparent rather than with white background.
>> See attached, any suggestions on how to fix this? I've tried a couple 
>> of things, none have worked so far.
>> Cheers,
>> Jatin
>> <plot_Trudy_precip.ncl><Trudy_precip_map.pdf>_______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
Dr. Jatin Kala
Lecturer in Atmospheric Science
Murdoch University,Perth, Western Australia
Tel: (+618) 9360 6297
http://www.jatinkala.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160222/6d758967/attachment.html 
-------------- next part --------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "/home/z3381484/hdrive/NCL/ncl-functions/cordex_grid_plot_functions.ncl"
load "/home/z3381484/hdrive/NCL/ncl-functions/lambert_grid_plot_functions.ncl"
load "/home/z3381484/hdrive/NCL/ncl-functions/querry_awap.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

; File Name : plot_Trudy_precip.ncl

; Purpose :

; Creation Date : 19-02-2016

; Last Modified : Mon 22 Feb 2016 20:52:07 AEDT

; Created By : Jatin Kala (Jatin.Kala.JK at gmail.com)

function fill_background(wks,plot,color)
local xmin,xmax,ymin,yma,gres,xbox,ybox
begin
  getvalues plot
    "trXMinF"  : xmin
    "trXMaxF"  : xmax
    "trYMinF"  : ymin
    "trYMaxF"  : ymax
  end getvalues

  xbox = (/xmin,xmax,xmax,xmin,xmin/)
  ybox = (/ymin,ymin,ymax,ymax,ymin/)

;---Resources for filling the polygon
  gres                 = True
  gres at gsFillColor     = color
  gres at tfPolyDrawOrder = "PreDraw"    ; This is necessary so that the 
                                      ; fill doesn't cover the curves.
;  print(xbox + " " + ybox)
;---Attach polygon to existing plot and return
  dum = gsn_add_polygon(wks,plot,xbox,ybox,gres)
  return(dum)
end




begin
f = addfile("/srv/ccrc/data39/z3381484/Trudy_Papp/AWAP_Year_Precip_mean_2001_2014.nc","r")
precip = f->all_precip_mean_mask
precip at _FillValue = 9.96921e+36 
lat = f->lat2d
lon = f->lon2d
precip at lat2d = lat
precip at lon2d = lon

type = "pdf"
res = True
colmap = "BlAqGrYeOrReVi200" ;"ViBlGrWhYeOrRe"
res at gsnSpreadColorEnd = 2
res at gsnSpreadColorStart = -1
res at cnFillOn              = True     ; turn on color fill
res at cnLinesOn             = False    ; turn of contour lines
res at cnLineLabelsOn        = False
res at gsnSpreadColors       = True     ; use full range of color map
res at gsnAddCyclic          = False    ; data already has cyclic point
res at gsnDraw               = False
res at gsnFrame              = False
res at mpMinLatF            = -36.0 ;min(lat2d)     ; range to zoom in on
res at mpMaxLatF            = -30.0 ;max(lat2d)
res at mpMinLonF            = 114.5 ;min(lon2d)
res at mpMaxLonF            = 121.0 ;max(lon2d)
res at mpGridSpacingF       = 1.0
res at mpDataBaseVersion = "HighRes"
res at lbLabelBarOn = True
res at cnLevelSelectionMode = "ManualLevels"
res at cnMaxLevelValF = 800.0
res at cnMinLevelValF = 100.0
res at cnLevelSpacingF = 25.0
res at tmXTOn = False
res at tmYROn = False

lats = (/-33.243963,  -34.288593 ,  -34.907939 /)
longs = (/115.93955,  116.450109, 117.037832/)
str = (/"a","b","c"/)
respl = True
respl at gsMarkerIndex = 16
resTx = True
resTx at txFontHeightF = 0.01

wks = gsn_open_wks(type,"pdf_out/Trudy_precip_map")
setvalues wks
      "wkBackgroundColor" : "white"
      "wkForegroundColor" : "black"
end setvalues 
gsn_define_colormap(wks,colmap)
map = gsn_csm_contour_map_ce(wks,precip,res)
dumx = gsn_add_polymarker(wks,map,longs,lats,respl)
dumt = gsn_add_text(wks,map,str,longs+0.1,lats+0.1,resTx)

; add Perth and Albany
mstring = "y"
fontnum = 35
xoffset = 0.0
yoffset = 0.0
ratio   = 1.0
size    = 1.0
angle   = 0.0
new_index = NhlNewMarker(wks, mstring, fontnum, xoffset, yoffset, ratio, size, angle)
respl at gsMarkerIndex = new_index
dum_p = gsn_add_polymarker(wks,map,(/115.8589,117.884/),(/-31.9522,-35.024/),respl)
resTx at txFontHeightF = 0.018
dum_perth = gsn_add_text(wks,map,"Perth",115.2,-32.0,resTx)
dum_alb = gsn_add_text(wks,map,"Albany",118.0,-35.5,resTx)

;draw map of australia to annotate
res1 = True
res1 at gsnDraw = False
res1 at gsnFrame = False
res1 at mpMinLatF = min(lat)
res1 at mpMaxLatF = max(lat)
res1 at mpMinLonF = min(lon)
res1 at mpMaxLonF = max(lon)
res1 at tmXTOn = False
res1 at tmXBOn = False
res1 at tmYROn = False
res1 at tmYLOn = False
res1 at mpFillOn = False
res1 at mpOutlineBoundarySets = "National"
res1 at mpDataBaseVersion = "MediumRes"            ; choose higher resolution
res1 at mpDataSetName = "Earth..4"                 ; choose most recent boundaries
res1 at mpOutlineSpecifiers = "Australia:states"
; make it smaller
res1 at vpHeightF = 0.2
res1 at vpWidthF = 0.2
res1 at mpLandFillColor         = "Grey"
res1 at mpOceanFillColor        = "White"
res1 at mpInlandWaterFillColor  = "White"

map_aus = gsn_csm_map_ce(wks,res1)
; add grid
resl = True
resl at gsLineDashPattern = 1
resl at gsLineThicknessF = 1.5
dum1 = gsn_add_polyline(wks,map_aus,(/res at mpMinLonF, res at mpMinLonF/),(/res at mpMinLatF,res at mpMaxLatF/),resl)
dum2 = gsn_add_polyline(wks,map_aus,(/res at mpMaxLonF, res at mpMaxLonF/),(/res at mpMinLatF,res at mpMaxLatF/),resl)
dum3 = gsn_add_polyline(wks,map_aus,(/res at mpMinLonF, res at mpMaxLonF/),(/res at mpMinLatF,res at mpMinLatF/),resl)
dum4 = gsn_add_polyline(wks,map_aus,(/res at mpMinLonF, res at mpMaxLonF/),(/res at mpMaxLatF,res at mpMaxLatF/),resl)

resTx at txFontHeightF = 0.0125
dum5 = gsn_add_text(wks,map_aus,"Map area",121.5,-39.0,resTx)

; annoate
amres = True
amres at amJust = "TopRight"
amres at amParallelPosF = 0.5
amres at amOrthogonalPosF = -0.5
map_annno = gsn_add_annotation(map,map_aus,amres)
dum_white = fill_background(wks,map_aus,"White")

draw(map)
frame(wks)

delete([/wks,map/])
system("pdfcrop pdf_out/Trudy_precip_map.pdf pdf_out/Trudy_precip_map.pdf")


end ; this ends begin


More information about the ncl-talk mailing list