next up previous contents index
Next: Two x axes Up: GRAPH EXAMPLES Previous: Plotting a vector

A graph with two y axes

  

  

figure4815

This example illustrates one way to display two different y axes on a single graph. Suppose we have three vectors, a, b, and frequency and we want to plot a and b versus frequency on one set of axis scales, and then plot some function of a and b versus frequency in the same axis box, but with a different y-axis scale on the right. We also want to label the curves and the axes. Note: The REPLOT command does not work with this type of constructed graph.

Start by generating some ``data'' to plot, and then executing the 2yaxes.pcm script, passing the newly created vectors as parameters. This script allows you to try out any function of a and b.                                            

frequency=[1:90]
a=sqrt(frequenc)
b=frequency^0.3
@2yaxes frequency a b `abs(0.3*A-B)'


 ! this is the  2yaxes.pcm  script
 !
 xtemp = ?1    ! the x variable
 ytemp = ?2    ! the first y variable
 ztemp = ?3    ! the second y variable
 fnc   = ?4    ! an expression (string) variable
 set 
  rittic 0     ! turn off right side tics
  lintyp 3     ! choose a line type
 %xuaxis 85    ! move the right side in for numbers and label
  colour 1     ! 
  
 scale min(xtemp) max(xtemp) min([ytemp;ztemp]) max([ytemp;ztemp])
 graph xtemp ytemp
 set lintyp 5
 graph\-axes xtemp ztemp
 !
 lenf = len(xtemp)
 world\percent xtemp[10] ytemp[10] xloc1 yloc1         ! for labeling the curves
 world\percent xtemp[lenf-5] ztemp[lenf-5] xloc2 yloc2 ! 
 set 
  %xloc xloc1-2
  %yloc yloc1+2
  cursor -2 
 
 text varname(?2)
 set
  %xloc xloc2-2
  %yloc yloc2+2
  cursor -2 
 
 text varname(?3)
 get 
  %xuaxis xux
  %ylaxis ylx
  %yuaxis yux
  %yiticl yiticl
 
 set           
  xaxis 0      ! turn off both axes
  yaxis 0      !
  box 0        ! turn off the box
  lintyp 1     !
  colour 2     !
 
 scale min(xtemp) max(xtemp) min(fnc) max(fnc)
 graph xtemp fnc
 world\percent xtemp[lenf/2] (fnc)[lenf/2] xloc1 yloc1
 set
  %xloc xloc1-2
  %yloc yloc1-15
  cursor -2
 
 text `<c2>'//fnc          ! label the curve
 set 
    yitica -90             ! rotate the yaxis numbers
    ytica -90              ! rotate the yaxis tics
   %yiticl yiticl*1.2      ! move the numbers out a bit
   %xlaxis xux             ! move the y-axis to the right side
    yaxis 1                ! only turn on the y-axis
 
 graph\axesonly
 set
  %xloc 4
  %yloc (yux+ylx)/2
   cursor -10
   txtang 90
 
 text `<c1>'//varname(?2)//` and '//varname(?3) ! label the axes
 set
  %xloc 96
  %yloc (yux+ylx)/2
   cursor -10
   txtang -90
 
 text `<c2>'//fnc
 destroy xtemp ytemp ztemp xloc1 yloc1 xloc2 yloc2 fnc
 defaults