[ncl-talk] png with background transparent
Francesco Trotta
francesco.trotta4 at unibo.it
Mon Feb 26 17:29:52 MST 2018
Dear ncl-support
I'm generating a contour_map plot for the ocean temperature
I would like to generate a png with a background transparent beacause I want overlay the map on google map.
I'm using the following scripts but I got a white background
How can I get a transparent background?
thanks
Francesco
;============== open a file ========================================
wks = gsn_open_wks(typefile,namefile)
setvalues NhlGetWorkspaceObjectId()
"wsMaximumSize" : 300000000
end setvalues
;============== miscellanous =======================================
gsn_define_colormap(wks,colorsMap)
;============== map resources ======================================
res = True
;--- Title attributes -----------------------------------
res at tiMainFont = 0
res at tiMainPosition = "Center"
res at tiMainFontHeightF = 0.011
;res at tiMainOffsetYF = 0.01
;--- GSN attributes -------------------------------------
res at gsnDraw = False
res at gsnFrame = False
res at gsnMaximize = True
res at gsnAddCyclic = False
res at gsnSpreadColors = True
;--- Map attributes (window) ----------------------------
res at mpLimitMode = "LatLon" ;Zoom in on the plot area
res at mpMinLatF = minLatF
res at mpMaxLatF = maxLatF
res at mpMinLonF = minLonF
res at mpMaxLonF = maxLonF
;--- Map attributes (projection) ----------------------------
res at mpProjection = "mercator"
;--- Map attributes (land outlines) ---------------------
res at mpDataBaseVersion = "HighRes" ;use GMT coastline
res at mpOutlineOn = lmapOutlineOn ;turn on continental outlines
res at mpOutlineBoundarySets = "AllBoundaries" ;turn on country boundaries (all the boundaries database in use)
res at mpGeophysicalLineThicknessF = 2.5 ;thickness of outlines
res at mpGeophysicalLineColor= "Black" ;color of cont. outlines
res at mpOutlineDrawOrder = "PostDraw" ;draw continental outline last
res at mpFillOn = False ;turn on gray fill for continental background
res at pmTickMarkDisplayMode = "Always"
;--- Map attributes (lat/lon grid lines) ----------------
res at mpGridAndLimbOn = False ;turn on lat/lon lines
res at mpGridLineDashPattern = 2 ;... with xxxx lines
res at mpGridLineColor = "black" ;color of the lines
res at mpGridLatSpacingF = 10 ;space (in degree) between 2 lines
res at mpGridLonSpacingF = 10 ;idem
res at mpGridLineThicknessF = 2.0 ;thickness of the lines
res at mpGridAndLimbDrawOrder= "PostDraw" ;draw lat/lon lines last
res at mpLabelFontHeightF = 0.005 ;label font size
;--- contours attributes --------------------------------
res at cnFillOn = True ;areas between levels filled with color
res at cnFillMode = "AreaFill" ;AreaFill
res at cnLevelSelectionMode = "ManualLevels" ;set manual contour levels
res at cnMinLevelValF = minLevelVal ;set max contour level
res at cnMaxLevelValF = maxLevelVal ;set min contour level
res at cnLevelSpacingF = levelSpacing
res at cnLinesOn = False ;turn off the contour lines
res at cnLineLabelsOn = False ;turn off the line labels
res at cnLineLabelFontHeightF= 0.005
res at cnLineLabelDensityF = 1 ;label spacing when cnLineLabelPlacementMode != "Constant"
res at cnLineLabelFontAspectF= 1 ;shape of the line label. > 1 :thinner characters. < 1 :wider
res at cnLineLabelInterval = 1
res at cnInfoLabelOn = False ;turn off "CONTOUR FROM X TO X BY X" legend.
res at cnLabelMasking = True ;mask lines where label appear
res at cnConstFEnableFill = True ;allow constant values (1=sig) to fill
res at cnConstFLabelOn = False
;--- LabelBar attributes --------------------------------
res at lbLabelBarOn = llabbarOn
res at lbLabelsOn = llabbarLabelsOn
;res at lbTitleString = "("+field at units+")"
res at lbOrientation = "vertical" ; vertical label bar
;res at pmLabelBarHeightF = 0.7
res at lbTitlePosition = "Bottom"
res at lbAutoManage = False ; Necessary to control sizes
res at pmLabelBarWidthF = 0.1 ; default is shorter
;res at pmLabelBarHeightF = 0.1 ; default is taller
;res at lbLabelFontHeightF = .018 ; default is HUGE
res at lbPerimOn = False ; default has box
res at lbLeftMarginF = 0.0
res at lbTopMarginF = 0.0 ; eliminate any margin at the top and left of the colorbar
res at lbBottomMarginF = 0.0 ; eliminate any margin at the top and left of the colorbar
res at lbLabelOffsetF = .05 ; this specifies the offset between the colorbar and the labels as a fraction of vpWidthF
res at lbLabelAutoStride = True ; (optional) this ensures that labels do not overlap when the font height is made very large.
res at lbLabelFontHeightF = 0.015
res at lbTitleFontHeightF = 0.015
;res at lbLabelStride = 5 ; Label every 5th entry
if (ismissing(minLevelVal) .or. ismissing(maxLevelVal)) then res at lbLabelStrings = ""
else res at lbLabelStrings = "" + sprintf(labformatStr,fspan(minLevelVal,maxLevelVal, \
floattoint((maxLevelVal-minLevelVal)/levelSpacing)+1)) end if
;-------------- scalars attributes ----------------------
res at sfXArray = lon2d(0:ny-1,0:nx-1) ; abscisses
res at sfYArray = lat2d(0:ny-1,0:nx-1) ; ordonnees
;=== draw contour/contour lines ====================================
plot = gsn_csm_contour_map(wks,field(:,:),res)
draw(plot)
frame(wks)
system("convert -alpha off -background white -geometry "+typefile at wkWidth+"x"+typefile at wkHeight+ \
" -density 300 -trim "+namefile+".png "+namefile+".png")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180227/9c214b24/attachment.html>
More information about the ncl-talk
mailing list