comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Alternate plot scales
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Alternate plot scales [message #13888] Wed, 06 January 1999 00:00 Go to next message
Brad Gom is currently offline  Brad Gom
Messages: 49
Registered: August 1997
Member
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
Re: Alternate plot scales [message #14005 is a reply to message #13888] Mon, 11 January 1999 00:00 Go to previous message
Kevin P. Reardon is currently offline  Kevin P. Reardon
Messages: 2
Registered: January 1999
Junior Member
> Brad Grom 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.

Brad,

just playing around I came up with something like this that seems to be
at least in the general direction of what you were looking for. It ain't
pretty (in particular, the rounding of step is pretty ad hoc), but it
should at least give you some ideas on how to get what you want.

; create an X axis that runs from 50 to 10000
xaxis=(findgen(101)*99.5)+50

; plot data with no X axes
plot_oi,xaxis,findgen(100)+randomn(100,100)*1,$
xran=[max(xaxis),min(xaxis)],xsty=5,/ysty,ymargin=[10,2]

; choose a spacing (20 steps) and plot lower X axis
step=fix(((10^!x.crange(1)-10^!x.crange(0))/20.)/10.-0.5)*10
axis,xaxis=0,/xlog,xtickv=findgen(21)*step+10000,xticks=20

; choose a spacing (30 steps)
step=fix((((10^!x.crange(1))^2-(10^!x.crange(0))^2)/30.) $
/1000.-0.5)*1000.
; plot upper X axis, the square-root of the lower X-axis
axis,xaxis=1,xrange=(10^!x.crange)^2,/xlog,$
xtickv=findgen(31)*step+(10^!x.crange(0))^2,xticks=30

; plot detached X axis with normal logarithmic spacing
axis,1,-15,xaxis=0,xrange=[1/(10^!x.crange(1)),$
1/(10^!x.crange(0))],/xlog

; plot vertical lines
topticks=findgen(31)*step+(10^!x.crange(0))^2
for i=0,30 do plots,(sqrt([topticks(i),topticks(i)])),!y.crange

One could also use the XTICK_GET keyword to get the values for
each tickmarks, and then a similar FOR loop for the vertical lines.
I hope this helps a bit.

cheers,
kevin reardon
Osservatorio Astronomico di Capodimonte
Re: Alternate plot scales [message #14020 is a reply to message #13888] Fri, 08 January 1999 00:00 Go to previous message
wgallery is currently offline  wgallery
Messages: 32
Registered: December 1998
Member
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
Re: Alternate plot scales [message #14025 is a reply to message #13888] Thu, 07 January 1999 00:00 Go to previous message
Brad Gom is currently offline  Brad Gom
Messages: 49
Registered: August 1997
Member
I believe Richard French sent you the link (thanks Richard).

I messed around a bit, and I think I figured out how to do it with AXIS.
My way seems to be quite cumbersome. I was hoping someone had a slick
routine that, given the function for the alternate x-axis, would
calculate (or interpolate) the corresponding alternate y-axis, and pick
aesthetically spaced tick intervals.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Special Functions
Next Topic: Re: Layered draw widget?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:43:00 PDT 2025

Total time taken to generate the page: 0.00729 seconds