Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Graphs with tk

by Lhamo_rin (Friar)
on Jun 18, 2005 at 00:57 UTC ( [id://467912]=perlquestion: print w/replies, xml ) Need Help??

Lhamo_rin has asked for the wisdom of the Perl Monks concerning the following question:

I need to graph several thousand data points and I would like to try it with tk. Does anybody have any examples of tk code that may help me get started?

Replies are listed 'Best First'.
Re: Graphs with tk
by davidrw (Prior) on Jun 18, 2005 at 01:09 UTC
    Why Tk? You could always just use GD::Graph to create the image and then display it on a Tk::Canvas ..

    If you're on linux, i recommend taking a look at gnuplot to see it it meets your needs -- for example can generate .ps files that you just open w/ghostview. Completely depends on your GUI requirements.
Re: Graphs with tk
by zentara (Archbishop) on Jun 18, 2005 at 12:24 UTC
    Yeah, basically you just want to set up a Canvas and plot your points by making "tiny circles". Here is an example using Tk::Axis, which makes a nice cartesian axis for you. It is based on Canvas. If you need help on how to plot your "tiny circles", let me know. Just read "perldoc Tk::Canvas" and search for "createOval".

    I will mention one thing, if you have too many datapoints, you may find it slow to display. You probably can get around it by updating your Canvas after every 100 points or so, so you will see the graph being drawn.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Axis; # from Tk-Contrib-0.07 my $mw = MainWindow->new(); $mw->geometry("600x600+10+10"); #the axis widget is a canvas #the origin is in the upper left corner, #so the (0,0) point corresponds to (25,575) #in this example (600 - margin) my $axis = $mw->Axis( -background => 'white', -height => 600, -width => 600, -margin => 25, -tick => 10, #-tickfont => $tickfont, #-tst => $tst, #-width => $width, -xmin => 0, -xmax => 100, -ymin => 0, -ymax => 100, )->pack(); $axis->Tk::bind("<Button-1>", [ \&print_xy, Ev('x'), Ev('y') ]); MainLoop; sub print_xy { print "@_\n"; my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n" +; }

    I'm not really a human, but I play one on earth. flash japh
Re: Graphs with tk
by Courage (Parson) on Jun 18, 2005 at 05:55 UTC

      I agree that BLT has some very effective utilities for graphing, however I have been having difficulties locating and installing a Tcl ppd for my Windows XP workstation.

      I've tried both 5.6 and 5.8 versions of Perl obtained from Activestate, and although I've been able to use PPM to install the Tcl-Tk Perl module, I've been unable to install the Tcl module.

      To head off any questions -- I was unable to install the Tcl ppd, so I get error messages complaining about being unable to locate Tcl.pm. I HAVE been able to install the Activestate Tcl distribution, but without the Tcl module, this does me little good. Any thoughts on where I might find a finctional Tcl ppd. Without it, distributions such as BLT are useless to me on Windows.

        this problem is easy to understand, and hopefully easy to resolve.

        There were some versions of Tcl ppd, but I'll prepare a fresh build within a couple of days.

        Meanwhile, let me note that lack of "Tcl.pm" means that pefore using Tcl::Tk CPAN module you should install Tcl CPAN module, which in turn requires Tcl to be installed (and you already have it installed)

Re: Graphs with tk
by Ultra (Hermit) on Jun 18, 2005 at 10:01 UTC
    Along with Perl/Tk you have a program, called widget that contains plenty of Tk examples, and source code
    Run it, it should get you started.
    Dodge This!
Re: Graphs with tk
by Anonymous Monk on Jun 20, 2005 at 23:33 UTC
    To graph and manipulate large sets of data points maybe you can use PDL.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://467912]
Approved by davidrw
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found