Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Intro to plotting with perl

by ZWcarp (Beadle)
on Jan 03, 2012 at 17:25 UTC ( #946099=perlquestion: print w/ replies, xml ) Need Help??
ZWcarp has asked for the wisdom of the Perl Monks concerning the following question:

Hey all. I have been using MatLab and excel to make graphs for some science figures but have found this to be cumbersome. It is my intent to learn how to make basic plots right from the command line using perl or some variation. They don't need to be pretty... just quick and dirty.

Things as simple as line plots, scatter plots, date plots... etc. Could someone direct me to some reading material that explains how to do this from the command line using perl, or maybe for more advanced things, a perl script? Any help would be awesome ! Thanks for your time!

Comment on Intro to plotting with perl
Re: Intro to plotting with perl
by Lotus1 (Chaplain) on Jan 03, 2012 at 17:41 UTC
      This. If you want to make graphs for a scientific publication, use Gnuplot. Your other uppercase-f-Free options are Octave (who knows how it will turn out since they stopped using Gnuplot), some Python thing (SciPy, of which I know little), and doing it yourself by hand (learn PostScript or some other vector drawing language).

      However, the linked node has a bunch of extraneous garbage. (Also, it doesn't even work, since it doesn't bother to flush the temporary file before using it.) All you really need is some version of:

      open DATAFILE, ">$whatever"; # write data to DATAFILE close DATAFILE; open PLOT, "| gnuplot"; print PLOT <<EOS; ... p '$whatever' ... (gnuplot options) ... ... EOS close PLOT;

        Well don't use a temporary file then ;)

        Just use gnuplot's special file '-' and inline the data.

        I added a node to show how it's done to the above example at Re: Plot a spiral with gnuplot

        However, the linked node has a bunch of extraneous garbage.

        I don't see anything extraneous or any garbage. I found that node months ago when I was curious about gnuplot and found it to be short and sweet and to the point with helpful links.

        (Also, it doesn't even work, since it doesn't bother to flush the temporary file before using it.)

        It has been a while since I tried the code in that node but I just remember quickly having a plot of a pretty spiral without much (any) effort on my part.

Re: Intro to plotting with perl
by ~~David~~ (Hermit) on Jan 03, 2012 at 17:48 UTC
    You can use GD. here is an example using points:
    use GD::Graph::points; my $graph = GD::Graph::points->new; $graph->set( x_label => 'Label', y_label => 'Values', title => 'Label By Value', #cumulate => 1, dclrs => [ 'black', 'black','black','black','black','b +lack','black' ], borderclrs => [ qw(black black), qw(black black) ], bar_spacing => 4, transparent => 1, show_values => 1, ); my $gd = $graph->plot(\@data) or die $graph->error; open(IMG, ">","$graph_file") or die $!; binmode IMG; print IMG $gd->gif; close IMG;
Re: Intro to plotting with perl
by i5513 (Monk) on Jan 03, 2012 at 18:46 UTC
Re: Intro to plotting with perl
by TJPride (Pilgrim) on Jan 03, 2012 at 21:00 UTC
    You -could- just learn basic SVG (Scaled Vector Graphics) and then use that language to draw whatever you want. Then you can in turn use a Perl script to generate the SVG. Or you could use Javascript instead with a library such as Raphael and even animate it.
Re: Intro to plotting with perl
by luis.roca (Deacon) on Jan 04, 2012 at 01:44 UTC

    You can take a look at chapter 5 of Graphics Programming with Perl as well as chapter 8 of Mastering Algorithms with Perl. The first will introduce you to GD::Graph, gnuplot and PGPLOT. The second is, as the title implies, a little more involved but provides further examples to try out.

    PDL (Perl Data Language) comes with a command line interface and is supposed to be somewhat of a competitor to MATLAB. It may be a bit more than it seems like you're looking for but the documentation is really extensive and apparently includes (just from looking it over a few times) a thorough course.


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote
Re: Intro to plotting with perl
by tospo (Hermit) on Jan 04, 2012 at 09:27 UTC
    ++ for GD::Graph. I use that a lot to generate quick and dirty plots for scientific data analysis. They are not pretty but very easy to generate and I find GD::Tiler a very useful addition to the toolbox. It allows you to quickly aggregate lots of plots in a single image, which often makes it easier to compare them.
Re: Intro to plotting with perl
by pvaldes (Chaplain) on Jan 04, 2012 at 16:34 UTC

    Well, I have used gnuplot in the past, is correct and great but a little limited to my taste. You need to control and to specify all. Finally I get tired of if.

    ... on the other hand, R is awesome doing plots. You can call R from Perl easily.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946099]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2014-07-12 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls