[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to label minor tick marks on a log axis???



In article <3AA8F2D2.A614462D@noaa.gov>,
 Paul van Delst <paul.vandelst@noaa.gov> wrote:

>David Fanning wrote:
>> 
>> Paul van Delst (paul.vandelst@noaa.gov) writes:
>> 
>> > Sorry for the twenty questions today but how does one go about labeling 
>> > the minor tick marks on a log axis (or a linear one for that matter)? 
>> > Does such a simple thing require use of XYOUTS? 
>> > I've been futzing about with the X/YTICKS keywords which 
>> > does the job but makes the resulting axis spacings linear! MAN!
>> 
>> Here's a copy of an old newsgroup article by Martin that
>> hasn't made it to my web page yet:
>
>David (and Martin),
>
>Thanks, this is exactly what I wanted. Unfortunately my joy was short-lived 
>when I couldn't figure out how to shift the y-axis title over enough not to overwrite 
>my new fancy tick labels. Sigh. (Or, how come there's no X|Y|ZTITLE_OFFSET keyword to 
>PLOT to account for X|Y|ZTICKFORMAT='(a1)'?) Do you (or Martin?) have something in 
>your bag-o-tricks to do this? I looked at Martin's and your IDL webpage but didn't 
>see anything. The thought of having to futz about with CONVERT_COORD and XYOUTS to 
>allow simple shifting of an axis title makes me want to ....1.2.3.4.5....10 I better 
>go and get some coffee.
>
>I think the curmudgeon factor that Craig Markwardt has mentioned in the past 
>is starting to affect me.... :o(
>
>thanx again,
>
>paulv

One way to open the left margin for all plots using !p.multi is to set 
!x.omargin=[5,0] or so.  This is outside margin and adds to !x.margin.

In addition, I have a little routine for writing the titles with their 
own font size and color, attached below (please send improvements).  We 
use Martin Schultz's code for minor ticks (see 
<ftp://cdaweb.gsfc.nasa.gov/pub/CDAWlib/source/>) and I have continued 
to bug RSI to add labeling minor ticks on log plots with scales less 
than 2 decades or so.

Robert.M.Candey@gsfc.nasa.gov           1-301-286-6707 (286-1771 fax)
NASA Goddard Space Flight Center, Code 632
Greenbelt, MD 20771 USA   <http://nssdc.gsfc.nasa.gov/personnel/rcandey/>


pro plotLabel, title, yaxis=yaxis, xaxis=xaxis, color=color, font=font, $
        charsize=charsize, thickness=thickness
; Robert.M.Candey.1@gsfc.nasa.gov, 1995 June 21
; 1995 July 26, BC  changed font sizing

; print label on Y axis or X axis; use instead of ytitle to get control
;       over font, font size and color
; main problem is lack of knowledge of how big tick labels are
; title:                text to print as title of an axis (required)
; yaxis=yaxis:          0 for left Y axis, 1 for right (default=0)
; xaxis=xaxis:          0 for bottom X axis, 1 for top (default=none)
; color=color:          text character color index (default=!p.color)
; charsize=charsize:    text character size (default=1.0)
; font=font:           text character font (default=-1 for Hershey fonts)
; thickness=thickness:  text character thickness (default=1.0)

if n_elements(color) eq 0 then color = !p.color
if n_elements(font) eq 0 then font = !p.font

ticklength = 0.0
tickLabelsize = 1.0
if n_elements(charsize) eq 0 then begin
  charsize = 1.0
  if !p.charsize gt 0 then charsize = !p.charsize
  if !p.charsize gt 0 then tickLabelsize = !p.charsize
  if !p.ticklen lt 0 then tickLength = !p.ticklen
  if n_elements(xaxis) ne 0 then begin ; x axis label
    if !x.charsize gt 0 then charsize = !x.charsize * charSize
    if !x.charsize gt 0 then tickLabelsize = !x.charsize * tickLabelsize
    if !x.ticklen lt 0 then tickLength = !x.ticklen ; override p.ticklen
  endif else begin ; y axis label
    if !y.charsize gt 0 then charsize = !y.charsize * charSize
    if !y.charsize gt 0 then tickLabelsize = !y.charsize * tickLabelsize
    if !y.ticklen lt 0 then tickLength = !y.ticklen ; override p.ticklen
  endelse
endif
;if n_elements(charsize) eq 0 then charsize = 1.0

if n_elements(thickness) eq 0 then $
  if !p.charthick gt 0 then thickness = !p.charthick else thickness = 1.0

if n_elements(xaxis) ne 0 then begin ; xaxis label
  Xmid = (!x.window(1) - !x.window(0)) / 2. + !x.window(0)
  if xaxis eq 1 then begin ; top label
    ticklabelLen = 0.5 < (!y.omargin(1) + !y.margin(1)) ; characters
    maxTside = (1.0 - (!d.x_ch_size * charsize * 1.1)/!d.y_size) < 1.0
    Tside = (!y.window(1) + ticklength + $
     (!d.y_ch_size * tickLabelsize * tickLabelLen)/!d.y_size ) < maxTside
    xyouts, Xmid, Tside, title, alignment=0.5, charsize=charsize, $
        orientation=0, font=font, color=color, /normal
  endif else begin ; bottom label
    ticklabelLen = 2.5 < (!y.omargin(0) + !y.margin(0)) ; characters
;    minBside = ((!d.x_ch_size * charsize * 1.1)/!d.y_size) > 0.0
    minBside = 0.01
    Bside = (!y.window(0) - ticklength - $
     (!d.y_ch_size * tickLabelsize * tickLabelLen)/!d.y_size ) > minBside
    xyouts, Xmid, Bside, title, alignment=0.5, charsize=charsize, $
        orientation=0, font=font, color=color, /normal
  endelse
endif else begin ; yaxis label
  Ymid = (!y.window(1) - !y.window(0)) / 2. + !y.window(0)
  if n_elements(yaxis) ne 0 then if yaxis eq 1 then begin ; right label
    ticklabelLen = 1.5 < (!x.omargin(1) + !x.margin(1)) ; characters
    maxRside = (1.0 - (!d.y_ch_size * charsize * 1.1)/!d.x_size) < 1.0
    Rside = (!x.window(1) + ticklength + $
     (!d.x_ch_size * tickLabelsize * tickLabelLen)/!d.x_size ) < maxRside
    xyouts, Rside, Ymid, title, alignment=0.5, charsize=charsize, $
        orientation=90, font=font, color=color, /normal
;       orientation=270, font=font, color=color, /normal
  endif else begin ; left label
    ticklabelLen = 6.5 < (!x.omargin(0) + !x.margin(0)) ; characters
    minLside = ((!d.y_ch_size * charsize * 1.1)/!d.x_size) > 0.0
    Lside = (!x.window(0) - ticklength - $
     (!d.x_ch_size * tickLabelsize * tickLabelLen)/!d.x_size ) > minLside
    xyouts, Lside, Ymid, title, alignment=0.5, charsize=charsize, $
        orientation=90, font=font, color=color, /normal
  endelse
endelse

return
end ; plotlabel

-- 
Robert.M.Candey@gsfc.nasa.gov           1-301-286-6707 (286-1771 fax)
NASA Goddard Space Flight Center, Code 632
Greenbelt MD 20771 USA   <http://nssdc.gsfc.nasa.gov/personnel/rcandey/>