Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This is just so that I can refer to some example code when I tell people to use gnuplot (instead of for example the popular GD module) to draw plots.

use strict; use warnings; use 5.010; use IO::Handle; use File::Temp "tempfile"; my($T,$N) = tempfile("plot-XXXXXXXX", "UNLINK", 1); for my $t (100..500) { say $T $t*sin($t*0.1), " ", $t*cos($t*0.1); } close $T; open my $P, "|-", "gnuplot" or die; printflush $P qq[ unset key plot "$N" with lines lw 3 ]; <STDIN>; close $P; __END__

You need gnuplot installed on your computer to run this. Read the gnuplot manual if you want to control the plot, for example change its appeariance, use dates as one coordinate, or export the plot to an image file. Use empty lines to draw discontinuous line segments.

Update: other posts where I've recommended gnuplot are: Re: perl postscript, Re: Interface to Gnuplot ?, Re^2: Easy plotting ?, Re^3: measuring IN/OUT traffic on your computer, Re: Draw chart (recommended), Re: Matrix magic with Perl + Octave, R or MatLab?, Re: parse a csv file and create array of arrays and then plot the data, Re: Export Plots, Two questions for GD::Graph, Stacked Bar.

Update: see also other posts about gnuplot: Statistical Graphs with gnuplot and mod_perl, Chart::Gnuplot png format, Re: Intro to plotting with perl.

Update 2011-01-28: added the statement close $T; which fixes a possible bug where the handle $T is not flushed.


In reply to Plot a spiral with gnuplot by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2014-10-21 04:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (96 votes), past polls