Credits | Overview | Plotting Styles | Commands | Terminals |
---|
This terminal driver generates Tk canvas widget commands in one of the following scripting languages: Tcl (default), Perl, Python, Ruby, or REXX.
Syntax:
set terminal tkcanvas {tcl | perl | perltkx | python | ruby | rexx} {standalone | input} {interactive} {rounded | butt} {nobackground | background <rgb color>} {{no}rottext} {size <width>,<height>} {{no}enhanced} {externalimages | pixels}
Execute the following sequence of Tcl/Tk commands to display the result:
package require Tk # the following two lines are only required to support external images package require img::png source resize.tcl source plot.tcl canvas .c -width 800 -height 600 pack .c gnuplot .c
Or, for Perl/Tk use a program like this:
use Tk; my $top = MainWindow->new; my $c = $top->Canvas(-width => 800, -height => 600)->pack; my $gnuplot = do "plot.pl"; $gnuplot->($c); MainLoop;
Or, for Perl/Tkx use a program like this:
use Tkx; my $top = Tkx::widget->new("."); my $c = $top->new_tk__canvas(-width => 800, -height => 600); $c->g_pack; my $gnuplot = do "plot.pl"; $gnuplot->($c); Tkx::MainLoop();
Or, for Python/Tkinter use a program like this:
from tkinter import * from tkinter import font root = Tk() c = Canvas(root, width=800, height=600) c.pack() exec(open('plot.py').read()) gnuplot(c) root.mainloop()
Or, for Ruby/Tk use a program like this:
require 'tk' root = TkRoot.new { title 'Ruby/Tk' } c = TkCanvas.new(root, 'width'=>800, 'height'=>600) { pack { } } load('plot.rb') gnuplot(c) Tk.mainloop
Or, for Rexx/Tk use a program like this:
/**/ call RxFuncAdd 'TkLoadFuncs', 'rexxtk', 'TkLoadFuncs' call TkLoadFuncs cv = TkCanvas('.c', '-width', 800, '-height', 600) call TkPack cv call 'plot.rex' cv do forever cmd = TkWait() if cmd = 'AWinClose' then leave interpret 'call' cmd end
The code generated by gnuplot (in the above examples, this code is written to "plot.<ext>") contains the following procedures:
gnuplot(canvas)
takes the name of a canvas as its argument. When called, it clears the canvas, finds the size of the canvas and draws the plot in it, scaled to fit.
gnuplot_plotarea()
returns a list containing the borders of the plotting area (xleft, xright, ytop, ybot) in canvas screen coordinates. It works only for 2-dimensional plotting (`plot`).
gnuplot_axisranges()
returns the ranges of the two axes in plot coordinates (x1min, x1max, y1min, y1max, x2min, x2max, y2min, y2max). It works only for 2-dimensional plotting (`plot`).
You can create self-contained, minimal scripts using the standalone option. The default is input which creates scripts which have to be source'd (or loaded or called or whatever the adequate term is for the language selected).
If the interactive option is specified, mouse clicking on a line segment will print the coordinates of its midpoint to stdout. The user can supersede this behavior by supplying a procedure user_gnuplot_coordinates which takes the following arguments:
win id x1s y1s x2s y2s x1e y1e x2e y2e x1m y1m x2m y2m,
i.e. the name of the canvas and the id of the line segment followed by the coordinates of its start and end point in the two possible axis ranges; the coordinates of the midpoint are only filled for logarithmic axes.
By default the canvas is transparent, but an explicit background color can be set with the background option.
rounded sets line caps and line joins to be rounded; butt is the default: butt caps and mitered joins.
Text at arbitrary angles can be activated with the rottext option, which requires Tcl/Tk 8.6 or later. The default is norottext.
The size option tries to optimize the tic and font sizes for the given canvas size. By default an output size of 800 x 600 pixels is assumed.
enhanced selects enhanced text processing (default), but is currently only available for Tcl.
The pixels (default) option selects the failsafe pixel-by-pixel image handler, see also image pixels. The externalimages option saves images as external png images, which are later loaded and scaled by the tkcanvas code. This option is only available for Tcl and display may be slow in some situations since the Tk image handler does not provide arbitrary scaling. Scripts need to source the provided rescale.tcl.
Interactive mode is not yet implemented for Python/Tk and Rexx/Tk. Interactive mode for Ruby/Tk does not yet support user_gnuplot_coordinates.