Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple Ploting

2 views
Skip to first unread message

BRåDy

unread,
Sep 20, 2001, 1:59:01 AM9/20/01
to
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
-------

canvas .c create line (textfiledatapoints)
pack .c


Not sure how to get the data outta the text file and plot it out.

Morten Skaarup Jensen

unread,
Sep 20, 2001, 3:56:11 AM9/20/01
to
#something like:

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

Peter Lewerin

unread,
Sep 20, 2001, 4:00:46 AM9/20/01
to
> Can someone tell me a easy way to plot some data points stored in
> a text file:


# 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]]]]

BRåDy

unread,
Sep 20, 2001, 4:36:46 AM9/20/01
to
THANK YOU to BOTH Morten and Peter =)

Max Ischenko

unread,
Sep 20, 2001, 8:21:30 AM9/20/01
to

BRЕDy wrote:

> 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.

BRåDy

unread,
Sep 21, 2001, 3:27:08 AM9/21/01
to
Is it easy to start a timer so every 1min the plot is redisplayed
(UPDATED) ?

Bruce Hartweg

unread,
Sep 21, 2001, 3:40:36 AM9/21/01
to

"BRåDy" <blink...@prodigy.net> wrote in message news:3BAAEBE9...@prodigy.net...

> Is it easy to start a timer so every 1min the plot is redisplayed
> (UPDATED) ?

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


0 new messages