Plotting graphs using Perl

September 12th, 2007 | Categories: programming | Tags:

I am in the middle of a small project written using the Perl scripting language and I found myself wanting to be able to plot a graph. Now I have faced this problem before and last time I cheated and got my Perl script to talk to the superb open source plotting program, gnuplot. This worked just fine but for various reason I wanted to code the whole thing in Perl itself this time – no talking to external programs.

A bit of googling around and I hit upon the GD::Graph Perl module. Once I had this installed I was producing graphs in .png format in no time. Now the resulting plots are not the prettiest I have ever seen but they do the job and maybe with a bit of tweaking they can be made to look a bit nicer. An example Bar chart is shown below (the text is distorted due to resizing the image – not because that’s how it actually looks)

A lot of sample scripts are included with the package and over at you can see what all of the resulting plots look like. All in all it’s a nice little package and is still under active development.

  1. Seda
    June 26th, 2011 at 21:17
    Reply | Quote | #1


    I was trying to have a line graph in Perl and I want the graph starts form the origin. As you can see, there is a gap between 0 at x-axis and 0 at y-axis in general. I think you did this at I would cordially appreciate if you could let me know how to do it.

    Thanks in advance,