How to combine vectcl with Plotchart

Arjen Markus (20 november 2014) The VecTcl extension by Christian Gollwitzer is a wonderful tool to do numerical analysis or number crunching in general. It has one or two drawbacks, if you can call them that, that makes it not entirely trivial to use in combination with a package like Plotchart to visualize the results:

  • The current parser does not cope well with quoted strings
  • Plotchart uses aliased commands that are stored in a variable, i.e. "$p plot data ...", so the command is not a constant

The code below contains several simple ways to overcome these limitations. Not sure what is the best/most attractive/easiest to use/most intuitive way. Hence this page - let's discuss and then consolidate the interface. Right now: the plot is fixed (which needs to be relaxed) and the plot method is fixed (another thing that should be selectable).

# plot.tcl --
#     Attempt to use Plotchart within Vectcl
#     Problem: the current version of vectcl does not quite handle
#     character data, like the quoted string "data", so that a
#     workaround must be found. One way to do that is to use
#     an ordinary Tcl proc that invokes the actual plot command.
package require Plotchart
package require vectcl

namespace import vectcl::*

toplevel .t
pack [canvas .t.c -width 700 -height 400]
set p [::Plotchart::createXYPlot .t.c {0 10 2} {0 10 2}]

proc ::Plotchart::Plot {label x y} {
    $::p plot $label $x $y

proc plot2 {label x y} {
    $::p plotlist $label $x $y 

vproc plot {label x y} {
    for i=0:shape(x)-1 {

vproc calc {label} {
    x = {1 2 3 4 5}
    y = {2 3 6 7 0}

set label "data"
calc $label