In article <36943AAC.CF73BE02@uleth.ca>,
Brad Gom <gombg@uleth.ca> wrote:
> I'm looking for a way to draw a secondary plot scale. The problem is
> that I want the second axis scale to be a function of the first.
>
> For example, the lower x-axis is a standard linear scale, and the upper
> x-axis is the square of the lower axis. Now the tricky part: I want the
> tickmarks for the second axis to occur at regular -numeric- (not
> graphical) intervals.
>
> eg. if the lower scale had ticks at [4,5,6,7,8], then it would be
> trivial to have the upper axis with the corresponding ticks labeled
> [16,25,36,49,64]. What I want is for the ticks on the upper axis to
> occur at some interval like [20,25,30,35,40,45,50,55,60] so that their
> spacing on the plot gets tighter but the numeric interval is constant.
>
> Thanks
>
>
I have written a procedure I think will solve your problem. It is like axis
but the spaceing between the tick marks is non-linear--hence the name of the
procedure is non_linear_axis.pro. I use is for labeling plots with, say,
wavenumber on the bottom and wavelength on the top. To do this, use a call
to plot to generate the basic plot but with xstyle=!x.style+8 to suppress the
upper x axis. Then call non_linear_axis to draw the upper x axis.
The procedure can draw an x (top or bottom) or y (left or right) axis, with
labeling on the left or right (top or bottom), with title. You can control
the length of the tick marks and the format of the labels (numeric or ascii).
Complete documentation is included in the code.
Good luck.
;+ ; NAME: ; non_linear_axis ; ; ; PURPOSE: ; Draw an axis for a quantity
that varies non-linearly ; ; ; CATEGORY: ; Plotting ; ; ; CALLING SEQUENCE:
; non_linear_axis, ; ; ; INPUTS: ; v = fltarr(n_v): array of values
corresponding to existing axis ; u = fltarr(n_v): array of values u
corresponding to v: u = f(v) ; ; OPTIONAL INPUTS: ; ; ; ; KEYWORD PARAMETERS:
; pos = ??? something to do with positioning the labels but I can't remember
; just what ; format= format for axis labels. Default = '(I)' ; title =
title for axis. Default is no title ; yaxis = 1: indicates an y axis
(vertical) is to be drawn. Default: x axis ; charsize = size of characters.
Default = 1 ; flip = not set: characters printed for top x axis or right y
axis, ; set: characters printed for bottom x axis or left y axis ; tic_fac
= length of tick marks relative to default of 1 ; n_skip = preserve only
every n_skip'th label ; ; EXAMPLE: ; Let f be an array of frequency values
in wavenumbers and s be the ; corresponding spectrum. To plot the spectrum
versus wavenumber and then ; draw a wavelength scale on the top axis: ;
(Assume f goes from 2200 to 2500 cm-1. wavelength = 1e4/wavenumber) ;
plot,f,s,xstyle=8,ymargin=[5,5],xtitle='Wavenumber',ytitle=' Spectrum' ;
u=[4.1, 4.2, 4.3, 4.4, 4.5] ;lable the new axis with these values ;
non_linear_axis, 1e4/u, u, format = '(f5.1)', title = 'Wavelength' ; ; ;
MODIFICATION HISTORY: ; William Gallery, AER, Inc., May, 1997 ; Dec., 1998:
added n_skip parameter ; limited ticks and labels to range of existing axis
;- PRO Non_linear_axis, v, u, du, pos=pos, format=format, title=title,
yaxis=yaxis, $ charsize=charsize, flip=flip, tick_fac=tick_fac, $
n_skip=n_skip
IF n_elements(charsize) LE 0 THEN charsize = 1.
IF n_elements(yaxis) GT 0 THEN axis = 'y' ELSE axis = 'x'
IF n_elements(flip) LE 0 THEN BEGIN
sign = 1 ;characters above or to right of axis
orig = 1 ;top or right axis
ofset = 0 ;offset characters above or to right of axis
ENDIF ELSE BEGIN
sign = -1 ;characters below or to left of axis
orig = 0 ;bottom or left axis
ofset = 1 ;offset characters below or to left of axis
ENDELSE
if n_elements(tick_fac) le 0 then tick_fac = 1. ;scale factor for tickmarks
IF n_elements(pos) LE 0 THEN BEGIN
axis_coord = convert_coord(!X.crange, !Y.crange, /data, /to_data)
CASE axis OF
'x': pos = !Y.crange(orig) ;y position of x axis, bottom or top
'y': pos = !X.crange(orig) ;x position of y axis, right or left
ENDCASE
ENDIF
IF n_elements(title) LE 0 THEN title = ''
IF n_elements(format) LE 0 THEN fmt = '(I)' ELSE fmt = format
IF n_elements(n_skip) LE 0 THEN n_skip = 1
;;Limit ticks and labels to within the range of the existing axis
CASE axis OF
'x': w = where(u GE !x.crange(0) AND u LE !x.crange(1))
'y': w = where(u GE !y.crange(0) AND u LE !y.crange(1))
ENDCASE
uu = u(w)
vv = v(w)
n_vv = n_elements(vv)
;;Need the height of a character in data coordinates
ch_size = [!D.x_ch_size/(!D.x_size*!X.s(1)), $
!D.y_ch_size/(!D.y_size*!Y.s(1))]*charsize
;;Convert uu to a string array
s_u = strtrim(string(uu, format=fmt), 2)
;;Find length of longest element of s_u
s_len_max = max(strlen(s_u))
;;Draw axis line
CASE axis OF
'x': BEGIN
;;Draw the axis line
plots, !X.crange, [!Y.crange(orig), !Y.crange(orig)], /data
;;Plot tick marks for uu
FOR k=0, n_vv-1 DO BEGIN
plots, [vv(k), vv(k)], [ pos, pos-sign*ch_size(1)*tick_fac], /data
ENDFOR
;;Print the values of uu centered above the tick mark
FOR k=0, n_vv-1, n_skip DO $
xyouts, vv(k), pos+sign*(ch_size(1)+ofset)*0.4, $
/data, align=.5, charsize=charsize, s_u(k)
;;Print the title above the top axis
xyouts, total(!X.crange)/2., pos+sign*(ch_size(1)+ofset)*2, /data, $
align=.5, charsize=charsize*1.0, title
END
'y': BEGIN
;;Draw axis line
plots, [!X.crange(1), !X.crange(1)], !Y.crange, /data
;;Plot tick marks for u FOR k=0, n_vv-1 DO BEGIN plots, [pos,
pos+sign*ch_size(0)*.6*tick_fac], [vv(k), vv(k)], /data ENDFOR
;;Print the values of u to the right of the tick mark
FOR k=0, n_vv-1, n_skip DO $
xyouts, pos+sign*ch_size(0)*(s_len_max*orig+1), $
vv(k)-ch_size(1)*.4, /data, align=1, charsize=charsize, s_u(k)
;;Print the title outside the axis
xyouts, pos+sign*ch_size(0)*(s_len_max+3), total(!Y.crange)/2, $
/data, align=.5, charsize=charsize*1.0, orien=180+sign*90., title
END
ENDCASE
return
END
William O. Gallery wgallery@aer.com
Atmospheric & Environmental Research Voice(617) 349-2284
840 Memorial Drive (617) 547-6207
Cambridge, Massachusetts 02139 FAX (617) 661-6479
William O. Gallery wgallery@aer.com
Atmospheric & Environmental Research Voice(617) 349-2284
840 Memorial Drive (617) 547-6207
Cambridge, Massachusetts 02139 FAX (617) 661-6479
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
|