I would like to know if there is any tool available which I would like
to use for plotting the XY data through programatically.
I know that TCL/TK has some plotting routines but it doesnt contain
some rich features. I am looking for a more standard tool written in
TCL/TK that I can use directly.
Thanks
Joe..
You want to try BLT (http://wiki.tcl.tk/blt) which offers nearly
everything you need for plotting xy data.
It is, though, not written in Tck/tk, since it is a C extension, but it
is written for Tcl/tk so you use like any other extension within your
Tcl script. If you need a tool written in pure Tcl/tl (i.e. without any
binary compiled stuff) there is this page -> http://mini.net/tcl/13784
listing quite a few of them, all with more or less restrictions. There
is also a pure Tcl/Tk extension in tcllib (named plotchart:
http://wiki.tcl.tk/plotchart)
Torsten
I created a small plotting library, called "Tkcanvplot". It's hosted on
sourceforge: http://sourceforge.net/projects/tkcanvplot. Tkcanvplot
creates a coordinate system and one or several XY data traces on a Tk
canvas. It is possible to plot lines, and it will soon be possible to
plot bars and scatter graphs as well. The project is suited for small
and very big datasets, as the plotting is done on C level (my
applications of it need to plot around 150000-200000 data points at
minimum).
More features include zooming, scrolling in zoomed plots, axisline
labeling, determination of plot coordinates...
It is my pet project and I do it in my spare time - that is the reason
why there are no file releases yet. However, Tkcanvplot is close to
1.0, the only problem is, that documentation is still missing. As soon
as I have found enough time to write a small manpage, I will release
the 1.0 and create one or two HTML pages for
http://tkcanvplot.sourceforge.net/.
Until then, you can checkout the sources from CVS (instructions at:
http://sourceforge.net/cvs/?group_id=148464).
A short usage example:
-------
package require Tk
package require Tkcanvplot
canvas .c -width 400 -height 600
set vp [.c create viewport 0 0 400 600 -fill white -xaxismin 0 \
-xaxismax 100 -yaxismin 0 -yaxismax 100]
set data {0 0 1 1 2 2 3 3 4 4 50 60 70 80 90 100}
.c create trace $data -fill red -viewport $vp
pack .c -expand yes -fill both
-------
Eckhard
That doesn't mean everything tk related will show up - but at least a
dozen or so pages with examples, etc. are there.
This looks interesting. Can you comment on how Tkcanvplot compares
with BLT's graph and stripchart? One obvious difference is that BLT
provides widgets, while your graphs appear to be Tk canvas elements.
Juan Carlos---
#!/usr/bin/env tclsh
package require Tk
pack [canvas .c -width 200 -height 200]
.c create line {
10 100 20 120 30 90 40 130 50 160 60 190 70 180 80 160 90 100 100
120
} -fill red
#-- To let positive y go up instead of down:
.c scale all 150 100 1 -1
You may need to scale your data if they don't happen to match the pixel
given geometry.
More embellishments might include: drawing x and y scales; marking
points, adding a legend, etc... It's mostly pretty easy with the Tk
canvas itself.
Much of the code is based on ideas from Tkgraph, which seems to be no
longer maintained (at least it was difficult to find a working link),
and works only on Linux - maybe other Unices.
Yes, the graphs and viewports are canvas elements. So it is easy to add
descriptions, legends and other elements. It is also possible to put
more than one viewport on a canvas and this way to display e.g. two
similar graphs in the same x range and different y ranges. The fade
cross can be configured to cover all viewports on the canvas.
This was important for me, as well as the ability to plot huge amounts
of XY data, zooming and scrolling. I tried BLT once, but drawing 150000
data points was impossible - the same experience of course with pure Tcl
plot implementations. I switched to Plplot, which is a very good
plotting library. But Plplot has two big problems for me: only 16 colors
and not really good working zooming functionality. It is possible to
zoom, but then *everything* in the plot window gets zoomed: plot labels,
axis labels... looks very strange.
Since I need only a very small part of plplots functionality (which is
just drawing of XY data, no shapes, no 3D plots, no heat maps or world
maps...), I decided to start developing Tkcanvplot for just this
purpose: drawing big amounts of XY data as lines/bars/scatters in many
colors plus zooming, scrolling and smooth integration in the Tk
landscape. This is what Tkcanvplot aims to be.
I experienced no bugs so far, except that it is not always possible to
configure the tickintervals for the viewport (-xmajortick, -xminortick,
-ymajortick, -yminortick) - no time to trace it back yet. At creation
time of the viewport it is always possible. There might be some more
bugs, the extension needs more testing.
If you have more questions, you're welcome to ask :-).
Eckhard
Nice, but not what I was looking for. Zooming takes place in Tkcanvplot
by configuring -xaxismin, -xaxismax, -yaxismin and -yaxismax. This is
what I wanted - all graph labels inside a viewport and the axis labels
stay the same size while only the x/y ranges of the data display change.
What I furthermore plan to implement is postscript representation, so
that a canvas with Tkcanvplot items can be plotted...
Eckhard
Art
package provide app-junk 1.0
# hello.tcl
package require tclogl
package require Togl
package require utils
wm withdraw .
set data { { 100 2 } { 110 30} { 200 3} {170 6} }
set plot(initted) 0
set plot(bgColor) "0 0 0 1"
set plot(winTitle) "INL/DNL Profile of Digital board"
set plot(winDim) "400x400"
set plot(win) {}
set plot(glWid) {}
set plot(glWid,wid) 0
set plot(glWid,he) 0
set plot(axis,XLabel) "Data Number"
set plot(axis,YLabel) "DN Frequency"
set plot(axis,origin) "75 75"
set plot(axis,origin,labels) "30 30"
set plot(axis,origin,markings) "40 40"
set plot(axis,origin,markings,draw) 0
set plot(axis,color) "0 0 1"
set plot(axis,lineThickness) 2
set plot(axis,rightMargin) 100
set plot(axis,leftMargin) 100
set plot(bars,Color) "1 1 0"
set plot(bars,Color2) "1 0 1"
set plot(bars,width) 1
set plot(sim,volt) 0.0
set plot(arrName) data
set plot(minX) 10000000000
set plot(maxX) 0
set plot(maxY) 0
set plot(nPts) 0
proc plotInit { } {
global plot
catch { destroy $plot(win) }
set plot(initted) 1
}
proc plot { } {
global plot
plotInit
# GUI
set plot(win) [toplevel .t]
wm geom $plot(win) $plot(winDim)
wm title $plot(win) $plot(winTitle)
wm protocol $plot(win) WM_DELETE_WINDOW plotFinal
set plot(glWid) [togl $plot(win).toglwin -width 0 -height 0 -double
false \
-createproc plotCreate \
-displayproc plotDraw \
-reshapeproc plotReshape]
set plot(glWid) $plot(win).toglwin
pack $plot(glWid) -fill both -expand true
bind $plot(win) <Key-Escape> "console show ."
}
proc plotReshape { toglwin w h } {
global plot
plotCalculate
set plot(glWid,wid) $w
set plot(glWid,he) $h
}
proc plotDraw { toglwin } {
global plot
plotCalculate
$plot(glWid) makecurrent
eval glClearColor $plot(bgColor)
glClear GL_COLOR_BUFFER_BIT
glMatrixMode GL_MODELVIEW
glLoadIdentity
glMatrixMode GL_PROJECTION
glLoadIdentity
glOrtho $plot(minX) [expr $plot(maxX) + $plot(bars,width)] 0
$plot(maxY) -1 1
scan $plot(axis,origin) "%d %d" x y
set width [expr $plot(glWid,wid) - $x - $plot(axis,rightMargin) ]
set height [expr $plot(glWid,he) - $y - $plot(axis,leftMargin) ]
glViewport $x $y $width $height
# Draw the Bars
upvar #0 $plot(arrName) data
set i 0
foreach li $data {
scan $li "%d %d" x1 y2
set x2 $x1
incr x2 $plot(bars,width)
if { $i % 2 } {
glColor3fv $plot(bars,Color)
} else {
glColor3fv $plot(bars,Color2)
}
glRecti $x1 0 $x2 $y2
incr i
}
# Draw the Axis
glColor3fv $plot(axis,color)
drawOneLine "$plot(minX) 0" "$plot(minX) $plot(maxY)"
drawOneLine "$plot(minX) 0" "[expr $plot(maxX) + $plot(bars,width)] 0"
# Draw Ranges
scan $plot(axis,origin,markings) "%d %d" x Y
glViewport $x $Y $width $height
drawString $plot(minX) 0 $plot(minX)
# Draw Labels
scan $plot(axis,origin,labels) "%d %d" X Y
glViewport $x $Y $width $height
drawString $plot(minX) 0 $plot(axis,XLabel)
glColor3fv "1 0 0"
drawOneLine "$plot(minX) 0" "[expr $plot(minX) + 10 ] 0"
glFlush
}
proc plotCreate { toglwin } {
makeRasterFont
glShadeModel GL_FLAT
}
proc plotFinal { } {
exit
}
proc plotCalculate { } {
global plot
upvar #0 $plot(arrName) data
set plot(minX) 10000000000
set plot(maxX) 0
set plot(maxY) 0
foreach li $data {
scan $li "%d %d" x y
if { $x <= $plot(minX) } { set plot(minX) $x }
if { $x >= $plot(maxX) } { set plot(maxX) $x }
if { $y >= $plot(maxY) } { set plot(maxY) $y }
}
}
#
# Simulation portion
#
toplevel .sim
wm title .sim "Simulator"
pack [checkbutton .sim.cb -variable plot(sim,on) -command plotSimUpdate
-text "Simulate Data on" ]
proc plotSimUpdate { } {
global plot
if { $plot(sim,on) } {
plotSim
plotDraw dummyArg
after 2000 plotSimUpdate
}
}
proc plotSim { } {
global plot data
catch {unset data}
set DN_Mean [ expr int ( $plot(sim,volt) * pow(2,16 ) ) ]
for { set i 0 } { $i < 256 } { incr i } {
lappend vals [expr int ( rand ( ) * pow(2,5 ) + $DN_Mean) ]
}
array set temp {ignore ignore}
foreach val $vals {
if { [info exists temp($val) ] } {
incr temp($val)
} else {
set temp($val) 1
}
}
unset temp(ignore)
foreach val [lsort -integer [array names temp ] ] {
lappend data [list $val $temp($val) ]
}
}
plotInit
plot
### UTILS package starts here ###
package provide utils 1.0
# Purpose - add a basic font to opengl
# Useage - makeRasterFont
# glShadeModel GL_FLAT
#
set space {
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 }
set letters {
{0x00 0x00 0xc3 0xc3 0xc3 0xc3 0xff 0xc3 0xc3 0xc3 0x66 0x3c 0x18}
{0x00 0x00 0xfe 0xc7 0xc3 0xc3 0xc7 0xfe 0xc7 0xc3 0xc3 0xc7 0xfe}
{0x00 0x00 0x7e 0xe7 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xe7 0x7e}
{0x00 0x00 0xfc 0xce 0xc7 0xc3 0xc3 0xc3 0xc3 0xc3 0xc7 0xce 0xfc}
{0x00 0x00 0xff 0xc0 0xc0 0xc0 0xc0 0xfc 0xc0 0xc0 0xc0 0xc0 0xff}
{0x00 0x00 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xfc 0xc0 0xc0 0xc0 0xff}
{0x00 0x00 0x7e 0xe7 0xc3 0xc3 0xcf 0xc0 0xc0 0xc0 0xc0 0xe7 0x7e}
{0x00 0x00 0xc3 0xc3 0xc3 0xc3 0xc3 0xff 0xc3 0xc3 0xc3 0xc3 0xc3}
{0x00 0x00 0x7e 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x7e}
{0x00 0x00 0x7c 0xee 0xc6 0x06 0x06 0x06 0x06 0x06 0x06 0x06 0x06}
{0x00 0x00 0xc3 0xc6 0xcc 0xd8 0xf0 0xe0 0xf0 0xd8 0xcc 0xc6 0xc3}
{0x00 0x00 0xff 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0 0xc0}
{0x00 0x00 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xdb 0xff 0xff 0xe7 0xc3}
{0x00 0x00 0xc7 0xc7 0xcf 0xcf 0xdf 0xdb 0xfb 0xf3 0xf3 0xe3 0xe3}
{0x00 0x00 0x7e 0xe7 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xe7 0x7e}
{0x00 0x00 0xc0 0xc0 0xc0 0xc0 0xc0 0xfe 0xc7 0xc3 0xc3 0xc7 0xfe}
{0x00 0x00 0x3f 0x6e 0xdf 0xdb 0xc3 0xc3 0xc3 0xc3 0xc3 0x66 0x3c}
{0x00 0x00 0xc3 0xc6 0xcc 0xd8 0xf0 0xfe 0xc7 0xc3 0xc3 0xc7 0xfe}
{0x00 0x00 0x7e 0xe7 0x03 0x03 0x07 0x7e 0xe0 0xc0 0xc0 0xe7 0x7e}
{0x00 0x00 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0x18 0xff}
{0x00 0x00 0x7e 0xe7 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3}
{0x00 0x00 0x18 0x3c 0x3c 0x66 0x66 0xc3 0xc3 0xc3 0xc3 0xc3 0xc3}
{0x00 0x00 0xc3 0xe7 0xff 0xff 0xdb 0xdb 0xc3 0xc3 0xc3 0xc3 0xc3}
{0x00 0x00 0xc3 0x66 0x66 0x3c 0x3c 0x18 0x3c 0x3c 0x66 0x66 0xc3}
{0x00 0x00 0x18 0x18 0x18 0x18 0x18 0x18 0x3c 0x3c 0x66 0x66 0xc3}
{0x00 0x00 0xff 0xc0 0xc0 0x60 0x30 0x7e 0x0c 0x06 0x03 0x03 0xff}
}
proc makeRasterFont {} {
global fontOffset
glPixelStorei GL_UNPACK_ALIGNMENT 1
set fontOffset [glGenLists 128]
set j [CharToNum "A"]
set len [llength $::letters]
for { set i 0 } { $i < $len } { incr i } {
glNewList [expr $fontOffset + $j] GL_COMPILE
# glBitmap 8 8 0.0 0.0 9 0.0 [lindex $::letters $i]
glBitmap 8 13 0.0 2.0 10.0 0.0 [lindex $::letters $i]
glEndList
incr j
}
glNewList [expr $fontOffset + [CharToNum " "]] GL_COMPILE
glBitmap 8 13 0.0 2.0 10.0 0.0 $::space
glEndList
}
proc printString { s } {
global fontOffset
glPushAttrib GL_LIST_BIT
glListBase $fontOffset
set len [string length $s]
set sa [VectorFromString GLubyte $s]
glCallLists $len GL_UNSIGNED_BYTE $sa
$sa delete
glPopAttrib
}
proc drawOneLine { p1 p2 } {
scan $p1 "%d %d" x1 y1
scan $p2 "%d %d" x2 y2
glBegin GL_LINES
glVertex2f $x1 $y1
glVertex2f $x2 $y2
glEnd
glFlush
}
proc drawString { x y str} {
glColor3fv "1 1 1"
glRasterPos2i $x $y
printString [string toupper $str]
glFlush
}