[ncl-talk] plot xtick cluster problem

LSL lslrsgis at whu.edu.cn
Thu Mar 7 09:23:45 MST 2019


Hi everyone,


I have met a problem in batching figures generated by the ncl code. 
Since the second one, the xticks are all clusted in the left corner. Any 
solutions?


The code and figures are attached.


Thanks very much.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Timeseries_CMA_WRF_1Y_SITE-52118_lat_43.16_lon_94.42.png
Type: image/png
Size: 52446 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190308/a4ceeb1d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Timeseries_CMA_WRF_1Y_SITE-52112_lat_43.46_lon_95.08.png
Type: image/png
Size: 51476 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190308/a4ceeb1d/attachment-0001.png>
-------------- next part --------------
;   Plot time series of Daily Precipitation (20->20H) for one year selected
;   INPUT : CMA file SURF_CLI_CHN_MUL_DAY-PRE-13011-SITE-51469-TT.TXT
;   OUTPUT: Timeseries_CMA_1Y_labels.png
;   
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
; SITE NUMBER
  sSite="57809"


;--Read in site file within WRF Domain 01
  DIR="/home/lsl/Downloads/DATA/wrfout_2015/Processed/"
  flnm = "PREP-SITE-LIST-LAT-LON-XY.TXT"
  strs_site = asciiread(DIR+flnm,-1,"string")

  delim = " "
  nfields = str_fields_count(strs_site(0), delim)

  field_site = str_get_field(strs_site, 1, delim)
  field_lat_LIST = stringtofloat(str_get_field(strs_site, 2, delim))
  field_lon_LIST = stringtofloat(str_get_field(strs_site, 3, delim))
  field_X   = stringtofloat(str_get_field(strs_site, 4, delim))
  field_Y   = stringtofloat(str_get_field(strs_site, 5, delim))

  nSite = dimsizes(field_site)
  field_X_r = floattointeger(floor(field_X))
  field_Y_r = floattointeger(floor(field_Y))

  delete(field_X)
  delete(field_Y)
  delete(field_X_r)
  delete(field_Y_r)


;  do iSite=0,nSite-1
  do iSite=0,10-1
;  print(sSite)
;  print(field_site(iSite))
  sSite=field_site(iSite)

  print(sSite)
  print(".......................")

; Read in CMA Site TXT Time Series
  DIR="/home/lsl/Downloads/DATA/CMA/PRE/PRE/"
  nPoint=1009
  flnm = "SURF_CLI_CHN_MUL_DAY-PRE-13011-SITE-"+sSite+"-TT.TXT"  ;OPTION for site: 51469
  strs = asciiread(DIR+flnm,-1,"string")


  delim = " "
  nfields = str_fields_count(strs(0), delim)

  field_sit = str_get_field(strs, 1, delim)
  field_lat = stringtofloat(str_get_field(strs, 2, delim))*0.01
  field_lon = stringtofloat(str_get_field(strs, 3, delim))*0.01
  field_ele = stringtofloat(str_get_field(strs, 4, delim))*0.10

  field_YY  = stringtoint(str_get_field(strs, 5, delim))
  field_MM  = stringtoint(str_get_field(strs, 6, delim))
  field_DD  = stringtoint(str_get_field(strs, 7, delim))

  field_PRE208  = stringtofloat(str_get_field(strs, 8, delim))*0.10
  field_PRE820  = stringtofloat(str_get_field(strs, 9, delim))*0.10
  field_PRE2020 = stringtofloat(str_get_field(strs,10, delim))*0.10

  field_Q_PRE208  = stringtoint(str_get_field(strs, 11, delim))
  field_Q_PRE820  = stringtoint(str_get_field(strs, 12, delim))
  field_Q_PRE2020 = stringtoint(str_get_field(strs, 13, delim))

  tstart = 2015  ;OPTION
  tend   = 2015 ;OPTION

  yyyymm   = yyyymmdd_time(tstart, tend, "integer")
  yyyyfrac = yyyymmdd_to_yyyyfrac(yyyymm,0)   ; create fractional years for 
                                            ; plotting purposes
;  print(yyyymm)

  ;arr = random_uniform(-5.,10.,(tend-tstart+1)*12)	; create random 1D array
  print(dimsizes(field_PRE2020))
  if(dimsizes(field_PRE2020) .lt. 12419) 
  delete(strs)
  delete(flnm)

  delete(field_sit)
  delete(field_lat)
  delete(field_lon)
  delete(field_ele)

  delete(field_YY)
  delete(field_MM)
  delete(field_DD)

  delete(field_PRE208)
  delete(field_PRE820)
  delete(field_PRE2020)

  delete(field_Q_PRE208)
  delete(field_Q_PRE820)
  delete(field_Q_PRE2020)

    continue
  end if

  arr01 = field_PRE2020(11688+0:11688+365-1)
  arr01 at _FillValue = 3270
  arr01 = where(arr01 .eq. 3270, 0, arr01)
;  print(arr01)
;  print(field_PRE2020(11688+0:11688+365-1))
;  print(strs) 

  sLAT = field_lat_LIST(iSite)
  sLON = field_lon_LIST(iSite)

;  print(yyyyfrac)
  delete(strs)

  delete(field_sit)
  delete(field_lat)
  delete(field_lon)
  delete(field_ele)

  delete(field_YY)
  delete(field_MM)
  delete(field_DD)

  delete(field_PRE208)
  delete(field_PRE820)
  delete(field_PRE2020)

  delete(field_Q_PRE208)
  delete(field_Q_PRE820)
  delete(field_Q_PRE2020)


; Read in WRF Site TXT Time Series
  DIR_WRF="/home/lsl/Downloads/DATA/wrfout_2015/Processed/"
  fwrf=DIR_WRF+"TIMESERIES-PREP-SITE-"+sSite+".TXT"

  strs_wrf = asciiread(fwrf,-1,"string")
  field_ppt = stringtofloat(str_get_field(strs_wrf, 1, delim))
;  print(field_ppt)
  delete(strs_wrf)

  ;=================================================================================
  ;Plot two time series on one figure arr01/field_ppt
  wks = gsn_open_wks("png","Timeseries_CMA_WRF_1Y_SITE-"+sSite+"_lat_"+sLAT+"_lon_"+sLON)   ; send graphics to PNG file
	
  plot = new(2,graphic)	       ; Array to hold plots so we can panel them later.

  res           = True
  res at tiMainString           = "Precipitation Time Series (CMA OBS) SITE "+sSite+"_lat_"+sLAT+"_lon_"+sLON+")"
;  res at tiMainFont             = 0.5
  res at tiMainFontHeightF      = 0.020
  res at xyLineThicknessF       = 1.0            ; make thicker
  res at trXMinF   = tstart       ; starting point along X axis
  res at trXMaxF   = tend+1       ; ending point along X-axis
  res at trYMinF   =  0.0         ; starting point along Y axis
  res at trYMaxF   = 20.0         ; ending point along Y-axis
  res at vpWidthF  = 1.7          ; stretch the plot to be wider (in NDC units)
;  res at vpHeightF = 0.25         ; and not as tall
  res at vpHeightF = 0.20         ; and not as tall  
  res at vpXF      = 0.15         ; set the start point along the X-axis in NDC units
  res at gsnDraw   = False        ; do not draw the plot (plots will be paneled)
  res at gsnFrame  = False        ; do not advance the frame (plots will be paneled)
  res at gsnXYBarChart = True
	
  plot(0) = gsn_csm_xy(wks,yyyyfrac,arr01,res)
	
  res at tmXBFormat = "f"        ; remove the trailing ".0" 
  res at tiMainString           = "Precipitation Time Series (WRF SIM) SITE "+sSite+"_lat_"+sLAT+"_lon_"+sLON+")"
  res at tiMainFontHeightF      = 0.020
  plot(1) = gsn_csm_xy(wks,yyyyfrac,field_ppt,res)

  delete(res at tmXBFormat)
  delete(arr01)

  res at trXMaxF    = 2001
  res at tmXBMode   = "Explicit"
  res at tmXBValues = yyyyfrac(:12)     ; choose first 13 timesteps

  res at tmXBLabels = (/" Jan ~C~2000"," Feb ~C~2000"," Mar ~C~2000"," Apr ~C~2000", \
                     " May ~C~2000"," Jun ~C~2000"," Jul ~C~2000"," Aug ~C~2000", \
                     " Sep ~C~2000"," Oct ~C~2000"," Nov ~C~2000"," Dec ~C~2000", \
                     " Jan ~C~2001"/)
				    
 ; plot(2) = gsn_csm_xy(wks,yyyyfrac(:12),arr(:12),res)			    

  resP             = True
  resP at gsnMaximize = True
  gsn_panel(wks,plot,(/2,1/),resP)  

  end do
  delete(field_lat_LIST)
  delete(field_lon_LIST)
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Timeseries_CMA_WRF_1Y_SITE-52323_lat_41.48_lon_97.02.png
Type: image/png
Size: 51016 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190308/a4ceeb1d/attachment-0002.png>


More information about the ncl-talk mailing list