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

comment on

( [id://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 (recommended).

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found