[ncl-talk] how to add values on the grid cells when drawing raster contours?
Mary Haley
haley at ucar.edu
Sat Oct 18 10:41:06 MDT 2014
First, there are a couple of things wrong with your script:
1) You have 0.0 as a _FillValue, which will not work when contouring with
NCL.
You can fix this with:
var at _FillValue = default_fillvalue(typeof(var))
2) You shouldn't set the "lat2d" and "lon2d" attributes, because your data
is rectilinear, and already has coordinate arrays via "lat" and "lon".
3) To add text strings, you want to use gsn_add_text. Since you have
missing values in "var", it might be easier to convert "var" to 1D using
ndtooned, and then conform the lat and lon coordinate arrays to be the same
size as "var", using a combination of conform and ndtooned. You can then
use "ind" to get the index locations in "var1d" where the values are not
missing, and use the lat1d and lon1d as the locations of these strings:
;
; Create 1D arrays of lat,lon,var values so we can
; put a text string at each value that is not missing.
;
lat1d = ndtooned(conform(var,var&lat,0))
lon1d = ndtooned(conform(var,var&lon,1))
var1d = ndtooned(var)
ii = ind(.not.ismissing(var1d))
ntext = dimsizes(ii)
txres = True
txres at txFontHeightF = 0.008
txres at txJust = "CenterCenter"
txid = gsn_add_text(wks,plot,""+var1d(ii),lon1d(ii),lat1d(ii),txres)
draw(plot)
frame(wks)
I'll attach the full script so you can run it.
--Mary
On Sat, Oct 18, 2014 at 8:39 AM, LI Qi <liqi123sh at qq.com> wrote:
> Dear NCL,
>
> I'd like to ask how to add values on the grid cells like the right figure
> shown below?
>
>
>
>
>
> Attached are the script and data.
>
> Any advice will be greatly appreciated!
>
> Qi Li
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141018/3b42fb30/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B3691800 at 89A38E5D.B27B4254.jpg
Type: image/jpeg
Size: 16833 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141018/3b42fb30/attachment.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BE5E7705 at 89A38E5D.B27B4254.jpg
Type: image/jpeg
Size: 58770 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141018/3b42fb30/attachment-0001.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: raster_mod.ncl
Type: application/octet-stream
Size: 3086 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141018/3b42fb30/attachment.obj
More information about the ncl-talk
mailing list