PlotFunc TCL UTILITIES USER MANUAL PlotFunc
SYNOPSIS
Autogenerate X vs Y plot of a function
PACKAGE
TCLPLT
NAME
PlotFunc
USAGE
PlotFunc  wID pID FmT FunC BeG EnD dX {PoPs}
INPUT DEFINITIONS
wID - The window identifier of the window in which to output the plot.
pID - The plot identifier to associate with the plot.
FmT - The input format of the function being plotted. This is either ALGORITHM or PROCEDURE depending on whether the input is given as an algebraic formula or as a procedure which takes X as an input and returns Y.
FunC - The input function. If FmT is ALGORITHM then this is algebraic algorithm with $X used as the variable. If FmT is PROCEDURE then this is the name of a procedure which accepts X as an input an returns Y.
BeG - The starting X value to use in the function definition.
EnD - The ending X value to use in the function definition.
dX - The step size to use when advancing X from BeG to EnD.
PoPs - An array of plot options which are accepted by the procedure. The complete list of options is given in the procedure description below.
RETURN DEFINITION
None
DESCRIPTION
PlotFunc produces an XY plot of an the input function defined in InPuT. The function is output in the window wID which must have been opened prior to the call to PlotFunc and any LOG scaled axes must be set. The range set for the window axes is used only if the axis is not auto scaled in PlotFunc. PlotFunc will assigned the plot identifier pID to wID.
The input function can be either an algebraic formula or a procedure which takes X as an input and returns Y. An example of the first would be:
set InPuT "\$X * \$X - 2.0 * \$X + 1.0"
while an example of the second type would be
set InPuT Gaussian
where Guassian would be a procedure of the form
proc Gaussian { X } {
       ...
   return $Y
}
      
The Y array within PlotFunc is obtained by solving the input function by stepping X from BeG to EnD with a step size dX.
There are a number of options which can be set to add some customization to the output plot. These are set in the optional array PoPs. A complete listing of the options is given in the table below.
INDEX DEFAULT DESCRIPTION
XLAB "" The X axis label.
YLAB "" The Y axis label.
NCOL 255 Color to use for numerical labels. Can be any value from 0 to 255.
LCOL 255 Color to use for axis text labels. Can be any value from 0 to 255.
PSET YES Output and annotate the plot axes. Must be either YES or NO.
XAS NO Autoscale the X axis. Must be either YES or NO.
YAS YES Autoscale the Y axis. Must be either YES or NO.
XASOP "" The AutoScale option array to use when auto scaling the X axis.
YASOP "" The AutoScale option array to use when auto scaling the Y axis.
PFMT LINE The plot format. Must be LINE, SCATTER, or HISTOGRAM"
POPS [list 255] The plot option list to pass into the Plot2D call.
AX Xb The X axis to plot against. Must be either Xb or Xt.
AY Yb The Y axis to plot against. Must be either Yl or Yr.
XTIC BOTH Put up tick marks on both sets of X axes. If you are plan to plot against both sets of axes then this should be set to "".
YTIC BOTH Put up tick marks on both sets of Y axes. If you are plan to plot against both sets of axes then this should be set to "".
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
EXAMPLE 1: Examples of different plots.
# READ the GUI preference settings

GUIprefsRead

# SET a window size

set GphInfo(xsScrL) 600
set GphInfo(ysScrL) 500
set GphInfo(xScrL) 600
set GphInfo(yScrL) 500

# Define a procedure which returns a trig function.  This could be done
#   as an algorithm in PlotFunc also but this shows how to use a 
#   procedure as input.

proc Trig { A } {
   global RtoD

   set A [expr $A / $RtoD]

   set Y [expr cos($A) - sin(2 * $A) + cos(5.0 * $A)]
   return $Y
}

# START graphics

GraphicsOn TK RainBow

# ESTABLISH 2 graphics windows which will contain plots  The first one 
#   has its secondary Y axis (Yr) LOG scaled.

GenWindow 1 0.15  0.10 0.0 0.85 0.50  0.0 -6.0 1.0 0.0 6.0 10 0.0
SetAxis 1 SECONDARY HOLD .01 HOLD HOLD 1.0 HOLD HOLD LOG HOLD 0
GenWindow 2 0.15  0.55 0.0 0.85 0.95  0.0 0.0 1.0 0.0 360.0 10 0.0

# DEFINE an algorithmic expression to plot.

set InPuT "exp(-(\$X - 1.0) * (\$X - 1.0)/2.0)"

# SET all of the plot annotation in both plots to be 10pt

PLTinfoChg 1 ALL NUMBERS NSIZE 10
PLTinfoChg 1 ALL NUMBERS TSIZE 10
PLTinfoChg 2 ALL NUMBERS NSIZE 10
PLTinfoChg 2 ALL NUMBERS TSIZE 10

# START with the lower plot on the canvas.  Only output the tick marks
#   associated with the plot axis and also define some axis labels.

set P(YTIC) ""
set P(YLAB) YLABA
set P(XLAB) XLAB

# OUTPUT the plot

PlotFunc 1 1 ALGORITHM $InPuT -6.0 6.0 0.2 P

# PLOT the same data set against Yr - the log scaled axis.  Turn off the
#   XLAB since we already labeled the axis, change the YLAB, set the
#   Y plot axis to Yr and change the plot color.

set P(YLAB) YLABB
set P(XLAB) ""
set P(AY) Yr
set P(POPS) [list $GphInfo(Yellow)]

# OUTPUT the plot

PlotFunc 1 1 ALGORITHM $InPuT -6.0 6.0 0.2 P

# NOW plot something in the upper window definition.  Change the Y axis
#   we are plotting against back to Yl, want to put tick marks on both 
#   Y axes, assign a Y axis label, and set the plot color back to white.  

set P(AY) Yl
set P(YTIC) BOTH
set P(YLAB) YLABC
set P(POPS) [list $GphInfo(White)]

# OUTPUT the plot

PlotFunc 2 2 PROCEDURE Trig 0.0 360.0 1.0 P
      
Apr 7, 2007