Re: Problems with axis labels, reversing axis order, label bar

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Jan 25 2011 - 11:36:51 MST

Hi Helen,

This looks like a bug in the labelbar. Would you be able to provide me with your data so I could run the script here and check?

Try commenting out this line:

  res@lbLabelAutoStride = True

and let me know if your labels still don't show up.

--Mary

On Jan 25, 2011, at 4:30 AM, Helen Parish wrote:

> Mary - the suggestions you made for adjusting the plot worked very well, thanks. However, I am now having difficulty with the label bar. As mentioned before, I am aiming to make the plot shown in A) below as similar as I can in style to plot B) below. I want to make the scaling the same as in plot B), and to do this I need to put the label bar numbers right at the ends of the label bar, and also to produce a color scheme for the label bar and the plot itself which is as close as possible to the color scheme used in plot B). However, for some reason, I seem to get missing numbers in the second to largest and second to smallest labels on the label bar.
>
> To get the numbers to go right to the ends of the label bar, and to get only 15 different colors to appear rather than 17, I used the routine "ExcludeOuterBoxes". I also specified the levels on the color bar explicitly with "ExplicitLevels" and specified particular colors that I wanted using "colors = ...". In order to get the overall background of the plot to stay white, and the text to stay black, I found I had to make the first two colors white and black. I also seemed to have to put in extra dummy colors at each end so that the ones that appear in the label bar are correct at each end. However, I cannot seem to find a way to prevent the occurrence of missing numbers at each end of the label bar.
>
> Does anyone know what I can do to get all the numbers to appear on the label bar ?.
> I enclose my current script in C) below.
>
> Thanks,
> Helen.
>
> A)
> <sebfigall.pdf>
> B)
> <example2.jpg>
> C)
> ;***********************
> ; timeavlatht.ncl
> ;***********************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> ;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "/p/lscratchd/parish3/gsn_csm.ncl"
> ;***********************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> ; Keep all files open when have a lot of files :
> setfileoption("nc","SuppressClose",False)
>
> diri = "./"
> fili = systemfunc("cd "+diri+" ; ls zeusrand09125*.cam2.h0*nc")
> print(fili)
> nfili = dimsizes(fili)
>
> lev_p = (/ 91500., 90000., 87500., 80000., 67500., 50000., 30000., 20000., 10000., 5000., 3000., 1500., 750., 390., 20
> 0., 100., 50.,25., 14., 7., 3.5, 1.9, 0.95, 0.4, 0.1, 0.03 /)
>
> do nf = 0, nfili-1
>
> fi = addfile (diri+fili(nf), "r")
>
> diro = "./"
> filo = "uhelen"+nf+".nc"
> print(filo)
> system ("/bin/rm -f "+diro+filo) ; remove any pre-exist file
> fo = addfile (diro+filo, "c")
>
> hyam = fi->hyam ; read hybrid info
> hybm = fi->hybm
> hyai = fi->hyai ; read hybrid info
> hybi = fi->hybi
> PS = fi->PS
> P0mb = 0.01*fi->P0
> U = fi->U
> lat = fi->lat
>
> lev_p!0 = "lev_p" ; variable and dimension name the same
> lev_p&lev_p = lev_p ; create coordinate variable
> lev_p@long_name = "pressure" ; attach some attributes
> lev_p@units = "hPa"
> lev_p@positive = "down"
>
> Up = vinth2p (U, hyam, hybm, lev_p ,PS, 1, P0mb, 2, False)
> copy_VarAtts(U, Up)
> fo->U = Up ; write to netCDF file
>
> end do
>
> diri = "./"
> fili2 = systemfunc("cd "+diri+" ; ls uhelen*nc")
> print(fili2)
> nfili = dimsizes(fili2)
>
> f2 = addfiles (fili2,"r")
> U2= addfiles_GetVar(f2,fili2,"U")
>
> printVarSummary( U2 )
>
> dimt2 = dimsizes( U2 )
> ntim2 = dimt2(0)
> klvl2 = dimt2(1)
> nlat2 = dimt2(2)
> mlon2 = dimt2(3)
>
> uavg = dim_avg_Wrap(U2)
>
> uavg_reorder = uavg(lev_p | :, lat | :, time | :) ; (lev,lat,time)
>
> utimeav = dim_avg_Wrap(uavg_reorder) ; (lev,lat)
>
> ;***********************
> ; Create Plot
> ;***********************
> wks = gsn_open_wks ("pdf", "sebtest" ) ; open workstation
> ; gsn_define_colormap(wks,"rainbow") ; choose colormap
>
> res = True
> res@cnFillOn = True
> res@lbLabelAutoStride = True
> res@lbOrientation = "Vertical"
> res@gsnMaximize = True ; if [ps, eps, pdf] make large
> res@gsnSpreadColors = True ; span color map
> res@gsnPaperOrientation = "Portrait"
>
> nt = 3 ; choose a time
>
> UTIMEAV = conform(uavg_reorder,utimeav,(/0,1/)) ; (lev,lat,time)
>
> work = utimeav(:,:) ; time average at all levels and latitudes
>
> res@gsnLeftString = ""
> res@gsnRightString = ""
>
> res@lbLabelPosition = "Left"
>
> res@pmTitleZone = 3
> res@pmLabelBarOrthogonalPosF = 0.05
>
> delete( utimeav&lat@units)
> utimeav&lev_p = utimeav&lev_p*100
> utimeav&lev_p@units = "Pa"
>
> res@tiXAxisString = "Latitude"
> res@tiYAxisString = "Pressure (Pa)"
>
> res@gsnYAxisIrregular2Log = True ; set y-axis to log scale
>
> res@tmXBMajorOutwardLengthF = 0.0 ; draw major x-axis tickmarks inward
> res@tmXBMinorOutwardLengthF = 0.0 ; draw minor x-axis tickmarks inward
> res@tmYLMajorOutwardLengthF = 0.0 ; draw major y-axis tickmarks inward
> res@tmYLMinorOutwardLengthF = 0.0 ; draw minor y-axis tickmarks inward
>
> res@trYMinF = 1.0e2 ; set minimum Y-axis value
> res@trYMaxF = 1.0e7 ; set maximum Y-axis value
>
> res@tmXBMode = "Explicit"
> res@tmXBValues = (/-50,0,50/)
> res@tmXBLabels = (/"-50","0","50"/)
> res@tmXBMinorValues = ispan(-90,90,10)
>
> res@cnLineLabelsOn = True
> res@cnLineLabelBackgroundColor = "Transparent" ; no bckgrnd around label
>
> res@cnLevelSelectionMode = "ExplicitLevels"
> res@cnLevels = (/ -20,-5,0,5,10,15,20,25,30,35,40,45,50,70,100,150 /)
>
> colors = (/"white","black","black","black","purple4","purple3","blue3","blue",\
> "dodgerblue3","cyan","cyan3","springgreen","green2","green", \
> "chartreuse","yellow","orange","red","red"/)
>
> gsn_define_colormap(wks,colors) ; change colormap
>
> res@cnLabelBarEndStyle = "ExcludeOuterBoxes"
>
> res@trYReverse = True
>
> plot = gsn_csm_contour(wks, utimeav(lev_p | 22:0,lat | :), res ) ; (lev,lat)
> ; plot = gsn_csm_pres_hgt(wks, utimeav(lev_p | 0:20,lat | :), res ) ; (lev,lat)
>
> end
>
>
> On Jan 24, 2011, at 8:06 AM, Mary Haley wrote:
>
>>
>> On Jan 22, 2011, at 3:44 AM, Helen Parish wrote:
>>
>>> I am trying to adjust my plot to look as similar as possible in style to another plot (though the data itself is different). I am having difficulty adjusting some of the features, such as the labelling of the axes etc. Even though the style of my plot is now looking much closer to what I want, there are some things that I cannot seem to alter using any of the commands I have tried.
>>>
>>> In particular I am having difficulties trying to :
>>> 1) Reverse the plot from top to bottom, so that values corresponding to the largest pressures are at the bottom of the plot rather than the top
>>> 2) Reverse the direction of the pressure values on the y axis, so that the largest numbers are at the bottom of the plot
>>
>> Try
>>
>> res@trYReverse = True
>>
>> I see you have this commented out. Did it not work for you? It should work if you use in conjunction with gsn_csm_contour.
>>
>>
>>> 3) Change the values on the x-axis from the standard labelling to labelling just -50, 0 , and 50
>>
>> If you are getting "50N" type of labeling, this is because your latitude coordinate array has a "units" of "degrees_north". You can turn this off
>> by removing the units:
>>
>> delete( utimeav&lat@units)
>>
>>> 4) Change the values on the y-axis so the numbers are all multiplied by 100 (so that the values really are in Pascals rather than mbar)
>>
>> Multiple your Y coordinate array by 100:
>>
>> utimeav&lev_p = utimeav&lev_p*100
>> utimeav&lev_P@units = "Pa"
>>
>>
>>> 5) Move the numbers on the label bar from the right hand side to the left hand side of the bar (and put the numbers right at the ends of the bar)
>>
>> Try:
>>
>> res@lbLabelPosition = "Left"
>>
>>
>>> 6) Put black labels with numbers on some of the contours on the plot.
>>
>> res@cnLineLabelsOn = True
>>
>> --Mary
>>
>>>
>>> Plot A below is my current plot.
>>> Plot B below is the style of plot I am trying to produce.
>>> The text in C below is a copy of the current script I am using.
>>>
>>> Does anyone have any ideas on how to adjust these features ?.
>>>
>>> Thanks,
>>> Helen.
>>>
>>> A. My current plot, which I am trying to adjust:
>>> <sebfigb.jpg>
>>> B. The plot whose style I am trying to reproduce:
>>>
>>> <pastedGraphic.jpg>
>>> C. The script I am using to generate the plot in A.
>>>
>>> ;***********************
>>> ; timeavlatht.ncl
>>> ;***********************
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>> ;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> load "/p/lscratchd/parish3/gsn_csm.ncl"
>>> ;***********************
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>>
>>> begin
>>>
>>> diri = "./"
>>> fili = systemfunc("cd "+diri+" ; ls zeusrand09125*.cam2.h0*nc")
>>> print(fili)
>>> nfili = dimsizes(fili)
>>>
>>> lev_p = (/ 91500., 90000., 87500., 80000., 67500., 50000., 30000., 20000., 10000., 5000., 3000., 1500., 750., 390., 200., 100., 50.,25., 14., 7., 3.5, 1.9, 0.95, 0.4, 0.1, 0.03 /)
>>>
>>> do nf = 0, nfili-1
>>>
>>> fi = addfile (diri+fili(nf), "r")
>>>
>>> diro = "./"
>>> filo = "uhelen"+nf+".nc"
>>> print(filo)
>>> system ("/bin/rm -f "+diro+filo) ; remove any pre-exist file
>>> fo = addfile (diro+filo, "c")
>>>
>>> hyam = fi->hyam ; read hybrid info
>>> hybm = fi->hybm
>>> hyai = fi->hyai ; read hybrid info
>>> hybi = fi->hybi
>>> PS = fi->PS
>>> P0mb = 0.01*fi->P0
>>> U = fi->U
>>> lat = fi->lat
>>>
>>> lev_p!0 = "lev_p" ; variable and dimension name the same
>>> lev_p&lev_p = lev_p ; create coordinate variable
>>> lev_p@long_name = "pressure" ; attach some attributes
>>> lev_p@units = "hPa"
>>> lev_p@positive = "down"
>>>
>>> Up = vinth2p (U, hyam, hybm, lev_p ,PS, 1, P0mb, 2, False)
>>> copy_VarAtts(U, Up)
>>> fo->U = Up ; write to netCDF file
>>>
>>> end do
>>>
>>> diri = "./"
>>> fili2 = systemfunc("cd "+diri+" ; ls uhelen*nc")
>>> print(fili2)
>>> nfili = dimsizes(fili2)
>>>
>>> f2 = addfiles (fili2,"r")
>>> U2= addfiles_GetVar(f2,fili2,"U")
>>>
>>> printVarSummary( U2 )
>>>
>>> dimt2 = dimsizes( U2 )
>>> ntim2 = dimt2(0)
>>> klvl2 = dimt2(1)
>>> nlat2 = dimt2(2)
>>> mlon2 = dimt2(3)
>>>
>>> uavg = dim_avg_Wrap(U2)
>>>
>>> uavg_reorder = uavg(lev_p | :, lat | :, time | :) ; (lev,lat,time)
>>>
>>> utimeav = dim_avg_Wrap(uavg_reorder) ; (lev,lat)
>>>
>>> ;***********************
>>> ; Create Plot
>>> ;***********************
>>> wks = gsn_open_wks ("pdf", "sebfigc" ) ; open workstation
>>> gsn_define_colormap(wks,"rainbow") ; choose colormap
>>>
>>> res = True
>>> res@cnFillOn = True
>>> res@lbLabelAutoStride = True
>>> res@lbOrientation = "Vertical"
>>> res@gsnMaximize = True ; if [ps, eps, pdf] make large
>>> res@gsnSpreadColors = True ; span color map
>>> res@gsnPaperOrientation = "Portrait"
>>>
>>> UTIMEAV = conform(uavg_reorder,utimeav,(/0,1/)) ; (lev,lat,time)
>>>
>>> work = utimeav(:,:) ; time average at all levels and latitudes
>>>
>>> res@gsnLeftString = ""
>>> res@gsnRightString = ""
>>>
>>> res@pmTitleZone = 3
>>> res@pmLabelBarOrthogonalPosF = 0.05
>>>
>>> res@tiXAxisString = "Latitude"
>>> res@tiYAxisString = "Pressure (Pa)"
>>>
>>> res@gsnYAxisIrregular2Log = True ; set y-axis to log scale
>>>
>>> res@gsnMajorLatSpacing = 50
>>> res@gsnMinorLatSpacing = 10
>>>
>>> res@cnLevelSelectionMode = "ExplicitLevels"
>>> res@cnLevels = (/ -20,-5,0,5,10,15,20,25,30,35,40,45,50,70,100,150 /)
>>>
>>> ; res@trYReverse = True
>>>
>>> ; plot = gsn_csm_contour(wks, utimeav(lev_p | 0:20,lat | :), res ) ; (lev,lat)
>>> plot = gsn_csm_contour(wks, utimeav(lev_p | 20:0,lat | :), res ) ; (lev,lat)
>>> ; plot = gsn_csm_pres_hgt(wks, utimeav(lev_p | 0:20,lat | :), res ) ; (lev,lat)
>>>
>>> end
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by MailScanner, and is
>> believed to be clean.
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jan 25 11:37:01 2011

This archive was generated by hypermail 2.1.8 : Tue Jan 25 2011 - 14:22:15 MST