Re: questions about plotting title, field name, and units, thanks

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon Jun 07 2010 - 17:02:48 MDT

Hi Yi,
You could use a carriage return:
http://www.ncl.ucar.edu/Applications/title.shtml#ex2
(See example #2, by using a ~C~)

This would mean however that you would have to manually set the string.
There is no way in NCL to tell it to wrap the titles when they get to be
too long.

Alternatively, you can change the subtitle font heights
(gsnStringFontHeightF) to make them smaller.
Adam

On 06/07/2010 04:15 PM, Yi Wang wrote:
> Hi Friends,
> Thank you so much for your help. I tried that and it looks pretty good.
> However, now another problem come out: two subtitles overlapped (see the
> attachment). I think maybe plot the
> *"FIELD NAME: nLw_412" *
> **
> *and *
> **
> *"UNITS: " + **data_pre@units* <mailto:data_pre@units>
> (now the codes use *res@gsnLeftString* <mailto:res@gsnLeftString>* =
> "FIELD NAME: nLw_412" and* *res@gsnRightString*
> <mailto:res@gsnRightString>* = "UNITS: " + **data_pre@units*
> <mailto:data_pre@units>)
> in two different rows probably can solve this problem. But I don't know
> how to do this. Could you please help me see this? Thanks a lot.
> Best,
> Yi Wang
> The hdf file:
> ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/veer/MAP_DATA/files/OceanColor/OCTS/L2/O1996306152450.L2_GAC.hdf
> The ncl file:
> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> ; This is an example of a 2-D data field.
> ; It is assumed users know how to obtain information such as _FillValue
> from HDFView.
> ; For information about HDFView, visit
> http://www.hdfgroup.org/hdf-java-html/hdfview/.
> begin
> eos_file=addfile("O1996306152450.L2_GAC.hdf", "r") ; Read file.
> ; Since the file is not HDF-EOS2, it is not necessary to append .he2
> data_pre=eos_file->nLw_412 ; read data field
> ; Here, because the file is not HDF-EOS2, it is not necessary to append
> the group name
> data_pre@_FillValue=0h <mailto:data_pre@_FillValue=0h>
> data_pre@_FillValue=1h <mailto:data_pre@_FillValue=1h>
>
> theIntercept=data_pre@intercept <mailto:theIntercept=data_pre@intercept>
> ; intercept=0.0, given from the attributes of nLw_412
> theSlope=data_pre@slope <mailto:theSlope=data_pre@slope>; slope=0.0010,
> given from the attributes of nLw_412
> data=theIntercept+data_pre*theSlope
> ;data@long_name = data_pre@long_name <mailto:data_pre@long_name>
>
> lat=eos_file->latitude
> lon=eos_file->longitude
> dimsize = dimsizes(data)
> numlat = dimsize(0)
> numlon = dimsize(1)
> ; define new latitude
> nlat=new( (/numlat,numlon/), float)
> mlon=new( (/numlat,numlon/), float)
> numCol = eos_file@Number_of_Pixel_Control_Points
> <mailto:eos_file@Number_of_Pixel_Control_Points>
> valueInCell = eos_file->cntl_pt_cols
> step1 = valueInCell(2) - valueInCell(1) ;step1=8
> step2 = valueInCell(numCol-1) - valueInCell(numCol-2) ;step2=7
>
> do i = 0, numlat-1
> do j =0, numCol-1 ;numCol-1=50
> ;when j = 0
> if(j.eq.0)
> nlat(i,j) = lat(i,j)
> mlon(i,j) = lon(i,j)
> continue
> end if
> ;when j = 1, ..., numCol-2 ;numCol-2=49
> if((j.ge.1).and.(j.le.(numCol-2))) ;numCol-2=49
> count=step1*(j-1)+1 ;step1=8
> arr_fill=fspan(lat(i,(j-1)), lat(i, j), (step1+1)) ;step1=8
> nlat(i, count:count+(step1-1)) = (/ arr_fill(1:(step1)) /)
> ;step1=8
> arr_fill=fspan(lon(i,(j-1)), lon(i, j), (step1+1)) ;step1=8
> mlon(i, count:count+(step1-1)) = (/ arr_fill(1:(step1)) /)
> ;step1=8
> continue
> end if
> ;when j = numCol-1
> if(j.eq.(numCol-1)) ;numCol-1=50
> count=step1*(j-1)+1 ;step1=8
> array_fill=fspan(lat(i,(j-1)), lat(i, j), (step2+1)) ;step2=7
> nlat(i, count:count+(step2-1)) = (/ array_fill(1:(step2)) /)
> ;step2=7
> array_fill=fspan(lon(i,(j-1)), lon(i, j), (step2+1)) ;step2=7
> mlon(i, count:count+(step2-1)) = (/ array_fill(1:(step2)) /)
> ;step2=7
> continue
> end if
>
> end do
> end do
>
> data@lat2d=nlat <mailto:data@lat2d=nlat>
> data@lon2d=mlon <mailto:data@lon2d=mlon>
>
> xwks=gsn_open_wks("pdf","O1996306152450.L2_GAC_nLw_412_limitedArea") ;
> open workstation
> res=True ; plot mods desired
> res@cnFillOn=True <mailto:res@cnFillOn=True> ; enable contour fill
> res@gsnMaximize=True <mailto:res@gsnMaximize=True>; make plot large
> res@gsnPaperOrientation <mailto:res@gsnPaperOrientation> = "portrait" ;
> force portrait orientation
> res@cnLinesOn=False <mailto:res@cnLinesOn=False> ; turn off contour lines
> res@cnLineLabelsOn <mailto:res@cnLineLabelsOn> = False; turn off
> contour line labels
> res@gsnSpreadColors=True <mailto:res@gsnSpreadColors=True> ; use the
> entire color spectrum
> res@cnFillMode="RasterFill <mailto:res@cnFillMode=%22RasterFill>" ; faster
> res@lbOrientation="vertical <mailto:res@lbOrientation=%22vertical>" ;
> vertical labels
> res@cnMissingValFillPattern <mailto:res@cnMissingValFillPattern> = 0 ;
> missing value pattern is set to "SolidFill"
> res@cnMissingValFillColor=0 <mailto:res@cnMissingValFillColor=0>; white
> color for missing values
> res@lbLabelAutoStride <mailto:res@lbLabelAutoStride> = True ; ensure no
> label overlap
> res@mpLimitMode <mailto:res@mpLimitMode> = "LatLon"
> res@mpMinLatF <mailto:res@mpMinLatF> = min(data@lat2d
> <mailto:data@lat2d>) ; Set limits of map, based on the min/max of the
> dataset latitude/longitude
> res@mpMaxLatF <mailto:res@mpMaxLatF> = max(data@lat2d
> <mailto:data@lat2d>) ;
> res@mpMinLonF <mailto:res@mpMinLonF> = min(data@lon2d
> <mailto:data@lon2d>) ;
> res@mpMaxLonF <mailto:res@mpMaxLonF> = max(data@lon2d
> <mailto:data@lon2d>) ;
>
> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200") ; define colormap
>
> ;You should also make sure you have a .hluresfile in your home directory
> ;so you don't get any PLCHHQ error messages.
> ;see: http://www.ncl.ucar.edu/Document/Graphics/hlures.shtml
> *res@tiMainString* <mailto:res@tiMainString>* = "O1996306152450.L2_GAC.hdf"
> **res@gsnLeftString* <mailto:res@gsnLeftString>* = "FIELD NAME: nLw_412"
> **res@gsnRightString* <mailto:res@gsnRightString>* = "UNITS: " +
> **data_pre@units* <mailto:data_pre@units>
>
> plot=gsn_csm_contour_map_ce(xwks,data,res) ; plot on world map first
> delete(plot) ; cleaning up resources used
> delete(nlat)
> delete(mlon)
> delete(xwks)
> delete(data)
> delete(res)
> delete(eos_file)
> end
>
>
> On Mon, Jun 7, 2010 at 11:19 AM, Mary Haley <haley@ucar.edu
> <mailto:haley@ucar.edu>> wrote:
>
> There are a few ways you can do this.
>
> The "tiMainString" resource gives you a main title, and the three
> gsnLeftString, gsnCenterString, gsnRightString gives you three
> subtitles. You can use all four resources, or any combination of them.
>
> The gsnCenterString will end up directly under tiMainString.
>
> You can make these individual subtitles, or one long title.
>
> Here's one way you might do the subtitles with a main title:
>
> filename = *"A20021612002192.L3m_R32_NSST_4.hdf*
> <mailto:res@tiMainString=%22A20021612002192.L3m_R32_NSST_4.hdf>*"*
> res@gsnCenterString = "field name: l3m_data"
> res@gsnLeftString = "(units: " + eos_file@Units + ")"
> res@tiMainString = filename
>
> You can also combine them into one long title. For example.
>
> res@tiMainString = filename + ": field name: l3m_data (" +
> eos_file@Units + ")"
>
> You should also make sure you have a .hluresfile in your home
> directory so you don't get any PLCHHQ error messages.
>
> See:
>
> http://www.ncl.ucar.edu/Document/Graphics/hlures.shtml
>
> --Mary
>
>> *;;;;;;;;;;;the following codes have
>> problems;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*
>>
>> *res@tiMainString="A20021612002192.L3m_R32_NSST_4.hdf*
>> <mailto:res@tiMainString=%22A20021612002192.L3m_R32_NSST_4.hdf>*"
>>
>> **res@gsnCenterString="field*
>> <mailto:res@gsnCenterString=%22field>* name: l3m_data" ; create
>> center text*
>> *res@txString="(units* <mailto:res@txString=%22(units>*:" +
>> **eos_file@Units* <mailto:eos_file@Units>* + ")"; create title*
>
> On Jun 7, 2010, at 9:36 AM, Yi Wang wrote:
>
>> Hi friends,
>> I met some problems. I want to plot the title, the field name:
>> l3m_data, and the units: deg-C above the picture. The title, and
>> the field name can be hard codes, however, the unites need to be
>> obtained from the attributes. I post my codes and errors as
>> below. Could anyone please help me see the codes? You can download
>> the corresponding hdf file from
>> ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/veer/MAP_DATA/files/OceanColor/MODISA/L3SMI/A20021612002192.L3m_R32_NSST_4.hdf.
>> I hope to see the plot with text (see the attachment) when open
>> the pdf file which is created by the ncl codes. Thank you so much!
>> Best,
>> Yi Wang
>>
>> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> ; This is an example of a 2-D data field.
>> ; It is assumed users know how to obtain information such as
>> _FillValue from HDFView.
>> ; For information about HDFView, visit
>> http://www.hdfgroup.org/hdf-java-html/hdfview/.
>>
>> begin
>> eos_file=addfile("A20021612002192.L3m_R32_NSST_4.hdf", "r") ; Read
>> file.
>> ;Not an HDFEOS file.
>> ;For more information, consult section 4.3.2 of
>> http://hdfeos.org/software/ncl.php.
>> ;units=eos_file@Units
>> data_unsigned=eos_file->l3m_data; read data field
>> data_unsigned@_FillValue=65535h
>> <mailto:data_unsigned@_FillValue=65535h> ; 'h' is appended to
>> avoid type mismatching
>> theIntercept=data_unsigned@Intercept
>> <mailto:theIntercept=data_unsigned@Intercept> ; Intercept=-2.0,
>> given in the attributes of l3m_data
>> theSlope=data_unsigned@Slope
>> <mailto:theSlope=data_unsigned@Slope>; Slope=7.17185E-4, given in
>> the attributes of l3m_data
>>
>> data_signed=where(data_unsigned.lt.inttoshort(0),
>> abs(data_unsigned)+32767, data_unsigned) ;
>> ; Convert unsigned integer to signed integer for NCL to properly
>> handle
>> data=theIntercept+data_signed*theSlope
>> data!0="lat" ; This file does not contain geolocation fields.
>> data!1="lon" ; To properly display the data, the
>> latitude/longitude must be remapped from its metadata.
>> ; See http://www.ncl.ucar.edu/Applications/Scripts/regrid_10.ncl
>> for more information
>> nLat=eos_file@Number_of_Lines
>> <mailto:nLat=eos_file@Number_of_Lines> ;4320
>> nLon=eos_file@Number_of_Columns
>> <mailto:nLon=eos_file@Number_of_Columns> ;8640
>> latStep=eos_file@Latitude_Step
>> <mailto:latStep=eos_file@Latitude_Step> ;0.041666668
>> lonStep=eos_file@Longitude_Step
>> <mailto:lonStep=eos_file@Longitude_Step> ;0.041666668
>> latStartpoint=eos_file@SW_Point_Latitude
>> <mailto:latStartpoint=eos_file@SW_Point_Latitude> ;-89.979164
>> lonStartpoint=eos_file@SW_Point_Longitude
>> <mailto:lonStartpoint=eos_file@SW_Point_Longitude> ;-179.97917
>> lat=ispan(0,nLat-1,1)*latStep+latStartpoint
>> lon=ispan(0,nLon-1,1)*lonStep+lonStartpoint
>> ;about ispan, see
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/ispan.shtml
>> lat@units <mailto:lat@units> = "degrees_north"
>> ;lat@Latitude_Units="degrees_North" is wrong
>> ;lat@units="degrees_North" is also wrong
>> lon@units <mailto:lon@units> = "degrees_east"
>> ;lon@Longitude_Units="degrees_East" is wrong
>> ;lon@units="degrees_East" is also wrong
>> lat=lat(::-1) ; use north-to-south latitude ordering
>> data&lat=lat
>> data&lon=lon
>> xwks=gsn_open_wks("pdf","A20021612002192.L3m_R32_NSST_4_l3m_data")
>> ; open workstation
>> setvalues NhlGetWorkspaceObjectId() ; make maximum filesize larger
>> "wsMaximumSize" : 200000000
>> end setvalues
>> res=True ; plot mods desired
>> res@cnFillOn=True <mailto:res@cnFillOn=True> ; enable contour fill
>> res@cnLinesOn=False <mailto:res@cnLinesOn=False> ; turn off
>> contour lines
>> res@gsnSpreadColors=True <mailto:res@gsnSpreadColors=True> ; use
>> the entire color spectrum
>> res@cnFillMode="RasterFill <mailto:res@cnFillMode=%22RasterFill>"
>> ; faster
>> res@lbLabelAutoStride=True <mailto:res@lbLabelAutoStride=True> ;
>> ensure labels do not overlap
>> res@lbOrientation <mailto:res@lbOrientation> = "vertical" ;
>> vertical labels
>> res@cnMissingValFillPattern <mailto:res@cnMissingValFillPattern> =
>> 0 ; missing value pattern is set to "SolidFill"
>> res@cnMissingValFillColor=0 <mailto:res@cnMissingValFillColor=0>;
>> white color for missing values
>> ;res@gsnLeftStringFontHeightF=10 ; make text smaller
>> ;res@gsnCenterStringFontHeightF=10
>> ;res@gsnRightStringFontHeightF=10
>>
>> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200") ; define colormap
>> *;;;;;;;;;;;the following codes have
>> problems;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*
>>
>> *res@tiMainString="A20021612002192.L3m_R32_NSST_4.hdf*
>> <mailto:res@tiMainString=%22A20021612002192.L3m_R32_NSST_4.hdf>*"
>>
>> **res@gsnCenterString="field*
>> <mailto:res@gsnCenterString=%22field>* name: l3m_data" ; create
>> center text*
>> *res@txString="(units* <mailto:res@txString=%22(units>*:" +
>> **eos_file@Units* <mailto:eos_file@Units>* + ")"; create title*
>>
>> *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*
>>
>> ;print(eos_file@Units <mailto:eos_file@Units>)
>>
>> plot=gsn_csm_contour_map_ce(xwks,data,res)
>> delete(plot) ; cleaning up resources used
>> delete(lat)
>> delete(lon)
>> delete(xwks)
>> delete(data)
>> delete(res)
>> delete(eos_file)
>> end
>> *The errors are as below.*
>> *PLCHHQ - CHARACTER NUMBER 16 (l) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 18 (m) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 19 (_) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 20 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 21 (a) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 22 (t) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 23 (a) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 11 (d) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 12 (e) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 13 (g) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 14 (-) IS NOT A LEGAL FUNCTION CODE
>> PLCHHQ - CHARACTER NUMBER 16 ()) IS NOT A LEGAL FUNCTION CODE*
>> <problems.png>_______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
__________________________________________________
Adam Phillips 
asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
Climate and Global Dynamics Division         fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jun 7 17:02:53 2010

This archive was generated by hypermail 2.1.8 : Fri Jun 11 2010 - 09:33:24 MDT