nop has asked for the wisdom of the Perl Monks concerning the following question:

Snippet from the GD::Graph docs:
Options for graphs with a numerical X axis First of all: GD::Graph does not support numerical x axis the way it s +hould. Data for X axes should be equally spaced
I have x-y data where the x values are not equally spaced. Any suggestions for plotting these data (points connected by lines, or just lines) into a PNG file on WinNT? Thanks.

Replies are listed 'Best First'.
Re: PNG xy plots with unequal spaced x values
by Masem (Monsignor) on Mar 02, 2001 at 22:49 UTC
    I see there is Chart::Graph::GnuPlot, which will allow to take your data from perl and pass it to Gnuplot, which can then export it as a pbm or a gif file ; pbm|gif->png conversion is trivial to do. Gnuplot is required to be installed (as it looks like it just does a system call to it with the right parameters), and this is available for Win32. GnuPlot is not braindead in thinking that X data are text labels as most graphing software seems to think; instead, the default format tends to be the x-y scatter plots that you are looking to make.
Re: PNG xy plots with unequal spaced x values
by dws (Chancellor) on Mar 02, 2001 at 22:42 UTC
    Two years back I spent a month trying to bend an earlier incarnation of GD::Graph to my will. Based on that experience, with the caveat that my knowledge of the package is now stale, I would advise this: Consider the GD::Graph package as a starting point. Make your own copy, and modify it to suit your needs. I don't advise this in general, but this package may be an exception.

    I also had the problem of getting tick marks to behave for some quirky data, and would have preferred to just subclass parts of the package to get the behavior that I wanted. Unfortunately, I didn't find the package well structured from a "here are concrete classes that are well-structured for subclassing" point of view. Unless the code has since been restructured, you might run into the same. YMMV.

Re: PNG xy plots with unequal spaced x values
by Chmrr (Vicar) on Mar 03, 2001 at 04:13 UTC
    I have needed to do this multiple times, and always end up re-finding the wheel. ;> I suggest you look at Chart::Plot, which is designed to do this. As it's based off of the wonderful GD module, and even defaults to saving as PNG. I also know that it works under Win32 -- I wrote a program doing that just yesterday. ;>

     
    perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

Re: PNG xy plots with unequal spaced x values
by BrotherAde (Pilgrim) on Mar 03, 2001 at 07:15 UTC

    One way to do this would be to calculate the smallest common denominator of the distances between points on the X axis. You could then use that to make the X-values equally spaced. As for those X-values that then don't have a value, use simple triangulation.

    I hope I make myself reasonably clear. This is one of the moments where I would just make a small drawing in real life. If my explanation doesn't seem to make sense, drop me a line and I'll put some sort of drawing up on my webpage.

    Brother Ade