canvas .c create line (textfiledatapoints)
pack .c
Not sure how to get the data outta the text file and plot it out.
canvas .c
set ff [open [tk_getOpenFile] r]
while 1 {
set line [gets $ff]
if {"$line" == ""} {
break
}
scan $line %f,%f x y
if {[info exists x0]} {
.c create line $x0 $y0 $x $y
}
set x0 $x
set y0 $y
}
close $ff
pack .c
#Note that the y axis goes downwards in this example
#Morten
---------------------------
Evaluations of Linux Software
http://www.evalisoft.com
Reviews & Ratings of distros & programs
# first, create the canvas widget
pack [canvas .c]
# then, open the file
set file [open textfile.dat]
# read its contents
set coords [read $file]
# turn commas and newlines into space characters
set coords [string map {, { } \\n { }} $coords]
# and trim out whitespace before and after
set coords [string trim $coords]
# plot the line
.c create line $coords
# or, more succinctly:
pack [set c [canvas .c]]
$c create line \
[string trim \
[string map {, {} \\n { }} \
[read \
[open textfile.dat]]]]
> Can someone tell me a easy way to plot some data points stored in a text
> file:
> -------
> textfile
> -------
> 34, 48
> 37, 65
> 87, 45
> 76, 87
> -------
Another view: use excellent gnuplot package with sophisticated
plotting/printing capablities. I've used Tcl to generate data/config files
and then fed them to gnuplot.
--
BOFH excuse #79:
Look, buddy: Windows 3.1 IS A General Protection Fault.
certainly - use the after command to reschedule the read/draw code
here is an outline:
proc init {} {
# create the canvas, rest of GUI
# call plotting routine
plot
}
proc plot {} {
# open file
# read data
# close file
# remove old data
.canvas delete all
# plot new data
# reschedule auto-update
after 60000 plot
}
init
Bruce