TABLE OF CONTENTS
::pwtk::plot
SYNOPSIS
proc ::pwtk::plot {args} {
USAGE
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
- -xl XLABEL --- X-axis label
- -yl YLABEL --- Y-axis label
- -xr XRANGE --- X-axis range specified as XMIN:XMAX or {XMIN:XMAX} or "XMIN:XMAX"
- -yr YRANGE --- Y-axis range specified as YMIN:YMAX or {YMIN:YMAX} or "YMIN:YMAX"
- -xf XFORMAT --- format for X-axis (e.g. %.2f)
- -yf YFORMAT --- format for Y-axis (e.g. %.2f)
- -u USING --- Gnuplot's "using" plot specification
- -w WITH --- Gnuplot's "with" plot specification
- -e EXTRA --- extra Gnuplot commands/configuration, e.g., -e {set nokey; set title 'simple plot'}
- -t TERMINAL --- terminal for the plot
- -v --- visualize the generated image(s) (for file terminals)
ARGUMENTS
- DATAFN1 --- the 1st datafile or function to plot
- DATAFN2 --- the 2nd datafile or function to plot
- ...
PURPOSE
"plot" plots data from one or more datafiles or functions on the same plot. 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
- the name of created image (for file terminals)
- an empty string (for non-file terminals)
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 }