A Simple Plotting Routine

The function plot() is an easy way to display data which consist of x- and y-pairs.

GQE::plot( x => $x, 
           y => $y, 
           start => $x_start,           # optional, def. 0
           stop => $x_stop,             # optional, def. 1
           np => $np_max,               # optional, def. 1000
           xlabel => "x-descr.",        # optional, def. Position
           ylabel => "y-descr.",        # optional, def. Signal
           title => "Title",            # optional, def. name
           comment => "some text",      # optional
           name => "generic_name",      # optional, def. PlotScan
	); 

$name = GQE::plot( method => "getname"); # returns the GQE name

($max_x, $max_y) = 
  GQE::plot( method => "maximum");       # returns the coord. of the maximum

GQE::plot( method => "postscript",
           printer => "printerName");    # optional, default: $SYM{printer},
                                         #   $ENV{PRINTER}, $ENV{LPDEST}

GQE::plot( method => "reset");

GQE::plot( method => "write",            # create a fio-file
           file_name => "filename",      # optional 
           fio_params => "p1 val1 p2 val2 ...”, 
                                         # name/value pairs of fio parameters
           hexapod => "yes",             # optional, default 'no'
           motors => "yes");             # include motor positions, opt., def. 'no'

GQE::plot( x_ptr => \@array_x,           # passes arrays instead of scalars
           y_ptr => \@array_y,           #
           ...
	);

If plot() is used to pass scalars, the user supplies x- and y-values. They are appended to the existing data and displayed. x may start at high or at low values. The plot is resetted, if the x-values change their direction (plot() has been coded to display a signal during the adjustment moves of single motors). The plot can also be resetted, if the corresponding method (reset) is invoked.

Here is an example:

#!/usr/local/perl

use Spectra; 
use GQE; 

my $y = 0; 
my $x = 0; 
my $delta = 0.1; 
while(1)
{
    $y = sin( $x); 
    GQE::plot( x => $x, 
	       y => $y, 
	       xlabel => "Position"); 

    $let = keyw(); # read keystrokes

    last if( $let == 32); # the space bar terminates the loop

    $x += $delta if $let == 274 ; # up-arrow
    $x -= $delta if $let == 275 ; # down-arrow
}
return;

The following example shows how plot() is used to pass arrays.

#!/usr/local/perl

use Spectra; 
use GQE; 

@x_arr = ( 1 .. 1000);
@y_arr = ( 1 .. 1000);

foreach my $y (@y_arr)
{
    $y = sin($y/10);
}

GQE::plot( x_ptr => \@x_arr, 
	   y_ptr => \@y_arr, 
  	   name => "sinus");