next up previous contents index
Next: Non-linear user-defined axis Up: GRAPH EXAMPLES Previous: A graph with

Two x axes

   

This example illustrates one way to add tic marks at arbitrary user-defined locations on a second x-axis. See the Figure opposite. First, generate some ``data'' and create a vector with the locations of the tic marks, in graph units. Then the data is plotted, followed by the conversion of the tic mark locations into world units so the locations of the numbers to be drawn above the tic marks can be determined. The trick here is to plot the tic marks as if they were data.

user-x-axis

                               

 x   = [1:10]               ! fake some data
 y   = x^2                  ! 
 x2  = [1.2;2.5;4.3;8.9]    ! locations for tic marks (in graph units)
 lx2 = len(x2)              ! length of vector x2
 y2  = [1:lx2]              ! y2 = [1;2;3;4;...]
 set
  toptic 0                  ! turns off automatic tic marks on top axis
  pchar 2                   ! plotting character 2 (connected)
  autoscale on              ! autoscale the plot
 
 graph x y                  ! graph the data with numbers on bottom axis
 get
  %xnumsz xnumsz            ! x-axis number size (% of window)
  %ylaxis ylaxis            ! location of bottom of y-axis (% of window)
  %yuaxis yuaxis            ! location of top of y-axis (% of window)
  %xiticl xiticl            ! distance from x-axis to numbers (% of window)
   ylaxis ylaxisw           ! location of bottom of y-axis (world units)
   yuaxis yuaxisw           ! location of top of y-axis (world units)
   xiticl xiticlw           ! distance from x-axis to numbers (world units)
   ymin   ymin              ! number at bottom of y-axis
   ymax   ymax              ! number at top of y-axis
 
 !
 !  figure out where to plot the tic marks
 !
 y1 = xiticlw/(yuaxisw-ylaxisw)*(ymax-ymin)+ymax
 yloc = yuaxis+1.2*xiticl   ! y location for plotting the numbers
 set
  %txthit xnumsz            ! text height (% of window)
   cursor -2                ! centre justification
  %yloc yloc                ! y location for text (% of window)
   txtang 0                 ! text angle
   clip 0                   ! allow plotting outside of axis box
   pchar 0                  ! no plotting symbol
 
 world\percent x2 y2 xp yp  ! convert graph units to % world coordinates 
 do j = [1:lx2]             ! for each large tic mark
   set %xloc xp[j]
   text rchar(x2[j])                    ! draw the upper x-axis numbers
   graph\-axes [x2[j];x2[j]] [ymax;y1]  ! plot the tic marks on top of box
 enddo