Re: explicit x-axis labels with gsn_csm_lat_time

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 16 2010 - 14:29:15 MST

Hi Juliane,

When your data has coordinate arrays, then your X and Y axes will
start and end at exactly the min/max of these values.
NCL is unable to extrapolate outside the range of your coordinate
values, because if your values are irregular,
it can't assume which extrapolation method to use.

Your time values start at 33290131.5 and that's why you can't get a
tickmark at 33290000.

If you want your X axis to actually start at 33290000, you will need
to create a new data
array that has one extra value in the X (rightmost) dimension, and
you will need to create
a new time coordinate array with that extra value. You can put
missing values in the location
of your data array that corresponds with your new extra point.

There was a question on this awhile back that explains how to add the
extra point. See:

http://www.ncl.ucar.edu/Support/talk_archives/all/1571.html

Here's how it might look in your case. This is untested:

      dims = dimsizes(sdemo) ; Get dimension sizes of data
      ny = dims(0)
      nx = dims(1)

; Create new array with extra point in X direction
      new_sdemo = new((/ny,nx+1/),typeof(sdemo),sdemo@_FillValue)
      new_x = new(nx+1,typeof(sdemo&$sdemo!1$))

; Assign values to new sdemo array

      new_sdemo(:,0) = sdemo@_FillValue
      new_sdemo(:,1:nx) = (/sdemo/)

; Create new time dimension with extra point.
      new_x(0) = 33290000; Assign new value to new coord array

      new_x(1:nx) = sdemo&$sdemo!1$

; Set up new data array to have coordinate values.

      new_sdemo!0 = sdemo!0

      new_sdemo!1 = sdemo!1

      new_sdemo&$sdemo!0$ = sdemo&$sdemo!0$

      new_sdemo&$sdemo!1$ = new_x

--Mary

On Feb 16, 2010, at 11:43 AM, Juliane Otto wrote:

> Hello,
> *_/
> /_*I'm am creating a gsn_csm_lat_time-plot. I followed the example
> hov_4.ncl <http://www.ncl.ucar.edu/Applications/Scripts/hov_4.ncl> to
> set explicitly the x-axis labels. My plot looks fine (as attached).
> However, I want the x-axis to start with January (JAN).
>
> The range of the time dimension is:
>
> Variable: time (coordinate)
> Type: double
> Total Size: 96 bytes 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> Number Of Attributes: 2
> calendar : proleptic_gregorian
> units : day as %Y%m%d.%f
> (0) 33290131.5
> (1) 33290228.5
> (2) 33290331.5
> (3) 33290430.5
> (4) 33290531.5
> (5) 33290630.5
> (6) 33290731.5
> (7) 33290831.5
> (8) 33290930.5
> (9) 33291031.5
> (10) 33291130.5
> (11) 33291231.5
>
> I have tried the following. I enlarged the range with
> res@tmXBValues and
> set the respective labels with res@tmXBLabels. Still, the x-axis
> ranges
> from FEB to DEC.
>
> res@tmXBMode = "Explicit"
> res@tmXBValues = (/ 33290000. , 33290100. , 33290200. ,
> 33290300., 33290400., 33290500., 33290600., 33290700., 33290800.,
> 33290900., 33291000., 33291100., 33291200. /)
> res@tmXBLabels =
> (/"DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","N
> OV","DEC"/)
>
> Does anyone know how to solve this?
>
> Thanks!
> *_/
> /_*<lat_time.ps>
>
> load "/sw/sarge-ia32/ncarg-4.4.1s/lib/ncarg/nclscripts/csm/
> gsn_code.ncl"
> load "/sw/sarge-ia32/ncarg-4.4.1s/lib/ncarg/nclscripts/csm/
> gsn_csm.ncl"
> load "/sw/sarge-ia32/ncarg-4.4.1s/lib/ncarg/nclscripts/csm/
> contributed.ncl"
>
>
> ;****plot lat versus time
> *********************************************
>
> begin
>
>
> ;*********************************************
> ; read in data
> ;*********************************************
>
> path1="/scratch/local2/m220065/cosmos-landveg-no-nitrogen_2009-
> SEP-03/DV/jot0012/echam5/snowmasking/"
> pathout="/scratch/local2/m220065/cosmos-landveg-no-nitrogen_2009-
> SEP-03/results/"
> time="annual/"
> filename="strength_temperature_latime"
>
> x1 = addfile(path1 + "jot0012_BOT_6h_monmean.nc","r")
> printVarSummary(x1->tsurf)
>
> tsurf = x1->tsurf
>
> ;*********************************************
> ; manipulate data for plotting
> ;*********************************************
>
> shov = tsurf({lon|100:100},lat|:,time|:) ; put
> time last
> dims = dimsizes(shov)
>
> sdemo = onedtond(ndtooned(shov), (/dims(1),dims(2)/) )
> sdemo!0 = "lat"
> sdemo!1 = "time"
> sdemo&lat = tsurf&lat
> sdemo&time = tsurf&time
> sdemo@long_name = "surface temperature"
> sdemo@units = "C"
> sdemo = sdemo-273.15
>
> print(sdemo&time)
>
> ;*************************
> ; plotting parameters
> ;*************************
> wks = gsn_open_wks ("ps", "lat_time" )
>
> gsn_merge_colormaps(wks,"BlGrYeOrReVi200","rainbow+gray")
>
> res = True ; plot mods
> desired
> res@cnFillOn = True ; color on
> res@lbLabelStride = 1 ; every other label
> res@lbOrientation = "Vertical" ; vertical label bar
> res@pmLabelBarOrthogonalPosF = -0.04 ; move label
> bar closer to axis
> res@cnLinesOn = False ; turn off contour lines
>
> res@cnLevelSelectionMode = "ManualLevels" ; manual set
> levels
> res@cnMinLevelValF = -30 ; min level
> res@cnMaxLevelValF = 30 ; max level
> res@cnLevelSpacingF = 5 ; contour intervall
> res@cnFillColors = (/
> 84,95,74,64,115,128,144,160,175,180,239,233,215,212,1/)
>
> res@tmXBMode = "Explicit" ; Define own tick mark
> labels.
> res@tmXBValues = (/ 33290000. , 33290100. , 33290200. ,
> 33290300., 33290400., 33290500., 33290600., 33290700., 33290800.,
> 33290900., 33291000., 33291100., 33291200. /)
> res@tmXBLabels =
> (/"DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","N
> OV","DEC" /)
>
> res@gsnMajorLatSpacing = 10.
>
> res@tiMainString = "Surface temperature, AV, 100E" ; title
>
> res@vpXF = 0.12 ; default is 0.2
> (aspect ratio)
> res@vpYF = 0.8 ; default is 0.8
> res@vpHeightF = 0.4 ; default is 0.6
> res@vpWidthF = 0.75 ; default is 0.6
>
>
>
> plot = gsn_csm_lat_time(wks,sdemo({30:90},:),res)
>
>
>
> end_______________________________________________
> 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
Received on Tue Feb 16 14:29:27 2010

This archive was generated by hypermail 2.1.8 : Thu Feb 18 2010 - 10:33:29 MST