TABLE OF CONTENTS


::pwtk::plot

SYNOPSIS

proc ::pwtk::plot {args} {    

USAGE

    ::pwtk::plot ?OPTIONS?  DATAFN1  ?DATAFN2? ...

 where DATAFN1, DATAFN2... are either datafiles or functions to plot,
 and OPTIONS are:

    -xl XLABEL
    -yl YLABEL
    -xf XFORMAT
    -yf YFORMAT
    -xr XRANGE
    -yr YRANGE
    -u  USING
    -w  WITH
    -e  EXTRA
    -t  TERMINAL
    -v

OPTIONS

ARGUMENTS

PURPOSE

"plot" plots data from one or more datafiles or functions on the same plot. If the datafiles were created with the ::pwtk::write command, they are closed prior to being plotted.

This is meant as a fast way of plotting simple data. For a more elaborate and configurable plotting, use the ::pwtk::gp::plot object-oriented interface instead.

For an example, see the example in ::pwtk::scanpar.

RETURN VALUE

SOURCE

    variable write_fid
    variable plot_id
    
    # parse args

    plot_parseOpt_

    ifnotempty opt(u) { set opt(u) "u $opt(u)" }
    #ifnotempty opt(w) { set opt(w) "w $opt(w)" }
    ifset opt(xl) ''
    ifset opt(yl) ''
    
    # plot's name
    
    if { [llength $args] == 1 && [file exists $args] } {
        set head plot-[file rootname $args]
    } else {
        set id [incr ::pwtk::gp::plot_id]
        set head plot-$id
    }

    # plot
    
    finish $args
    
    foreach datafn $args {
        if { [file exists $datafn] } {
            # datafn is a file
            set width [expr { $opt(w) eq {} ? $::pwtk::gp::gp(datafile_with) : "w $opt(w)" }]
            append plot "[squote $datafn] $opt(u) $width, "
        } else {
            # datafn is a function, skip $opt(u)
            set width [expr { $opt(w) eq {} ? $::pwtk::gp::gp(function_with) : "w $opt(w)" }]
            append plot "$datafn $width, "
        }
    }
    set plot [string trim $plot {, }]

    set gp [::pwtk::gp::plot new $head.$opt(t)]
    $gp options [list xlabel [squote $opt(xl)] ylabel [squote $opt(yl)]]
    ifnotempty opt(xr) { $gp options [list xrange [rangequote $opt(xr)]] }
    ifnotempty opt(yr) { $gp options [list yrange [rangequote $opt(yr)]] }
    ifnotempty opt(xf) { $gp options [list format.x [squote $opt(xf)]] }
    ifnotempty opt(yf) { $gp options [list format.y [squote $opt(yf)]] }
    ifnotempty opt(e)  { $gp add $opt(e) }
    
    $gp plot $plot
    $gp exec
    set output [$gp outputs]
    $gp destroy
    
    displayPlots_ $opt(v) $opt(t) $output
    
    return $output
}