Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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!

Replies are listed 'Best First'.
Re: Intro to plotting with perl
by Lotus1 (Curate) 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 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 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 i5513 (Pilgrim) on Jan 03, 2012 at 18:46 UTC
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.

      For 2D, use grace. It'sbetter than gnuplot and you can easilyperl it, by creatinga grace file and even runningit.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946099]
Approved by Corion
[Corion]: Yay. Traditional finance situation averted. Bonds can be quoted in amounts (1_000_000 EUR) or per unit (1 unit). And a traditional error is to trade 2_000_000 piece when you meant to trade 2_000_000 EUR.
[Corion]: (one of my scripts simply catches high amounts and I phone people making that trade, ideally before the payment is due)
[Corion]: The sad thing is that my script sits at the end of the pipeline and can only look at the payments due today or tomorrow basically, while there are many more systems further up in the pipeline
[GotToBTru]: better late than never, I guess

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2017-03-29 11:29 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (347 votes). Check out past polls.