Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Drawing Graphs

by johnirl (Monk)
on Sep 12, 2002 at 11:22 UTC ( [id://197192]=perlquestion: print w/replies, xml ) Need Help??

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

Hey Monks
For my current project I will soon have to start creating Graphs. These graphs may be large and detailed and may need to be manipulated in a number of ways (as of yet unknown to me).
Anyway I've been looking arouns in CPAN and the module that seems best suited to my needs is GD::Graph.
Has anybody worked with this or other graph tools?
If you have how would you rate it against others?
Or what one would you use?

j o h n i r l .

Sum day soon I'Il lern how 2 spelI (nad tYpe)

Replies are listed 'Best First'.
Re: Drawing Graphs
by RMGir (Prior) on Sep 12, 2002 at 11:38 UTC
    What kinds of graphs? GD::Graph is for line/bar/pie type charts.

    For those kinds of charts, you may want to look at Chart::Graph::Gnuplot, or just drive gnuplot manually like I did here... My script used the default X11 output, but gnuplot will do png or postscript, I believe.

    If it's "nodes & lines" graphs, GraphViz may be more what you need.

    I'm not dissing GD::Graph; I've never used it, so I'm just suggesting alternatives I have used.
    --
    Mike

Re: Drawing Graphs
by Joost (Canon) on Sep 12, 2002 at 11:52 UTC
    This all depends on what kind of graphs you are talking about.

    I've used GD::Graph for simple 'business graphics' (pie charts, bar graphs etc) and it works quite well for those things. Also GD is nice for redering simple buttons etc.

    I've used Gimp for 'complex' graphics redering like semi-transparent text on background images with all kinds of filters. It's really good and very flexible but it did take me quite a long time to work out (not to mention the problems of installing everything on an X-less webserver).

    I've also used GraphViz for creating nice, renderings of graphs - the kind with nodes and vertices. The perl interface is nice and seems stable, but not 100% complete as far as I can see.

    There is a lot of stuff on CPAN i've never used, so maybe somebody else kan post his/her experiences here...

    HTH, Joost

    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: Drawing Graphs
by Jaap (Curate) on Sep 12, 2002 at 12:22 UTC
    If you want to use svg (scalable vector graphics, w3c's version of flash), you might wanna take a look at SVGGraph. It works very well (but i am biased).
Re: Drawing Graphs
by Jeppe (Monk) on Sep 12, 2002 at 14:40 UTC
    I am currently installing ploticus. It looks very complete - it can even visualize confidence intervals and outliers and such. I haven't started using it yet, but taking a look won't hurt you. Anybody else here using ploticus, btw?
      I took a look and it looks pretty cool even though you have to invoke it from the command line if you don't want to use it in CGI mode. It would be nice to have an object wrapper for this useful utility.

      Does anyone know whether there is an object wrapper for ploticus or am I going to have to write one?

      ~~~~~~~~~~~~~~~
      I like chicken.
Re: Drawing Graphs
by johnirl (Monk) on Sep 12, 2002 at 13:30 UTC
    I'm not to sure which graphs will best suit our needs in the future but what we are aiming for is extremly accurate line type graphs at the moment. But if your suggested tool can handle more than that, well so much better.

    Also if you could say why you're suggesting the tool you are that would really be helpful.

    j o h n i r l .

    Sum day soon I'Il lern how 2 spelI (nad tYpe)

      I say stick with GD::Graph. I do statistical reporting with lines, bars, and pie and the simple fill an xAxis array with datapoints equal to the number of n yAxis array datapoints then simply calling a "plot" method is simpley the easiest way. Especially if you are grabbing this data from the arrays that fetcharray in DBI so graciously creates for you. Good luck.

      Tradez
      "Never underestimate the predicability of stupidity"
      - Bullet Tooth Tony, Snatch (2001)
      You might also look at some of the line drawing abilities of Perl/Tk. I was able to draw graphs and was able
      to print them out on a PostScript printer. It will require that you calculate the x/y corordinates in your program.
      I don't know if this is what you want.
Re: Drawing Graphs
by talexb (Chancellor) on Sep 12, 2002 at 18:30 UTC
    I can recommend GnuPlot from my experience writing code to generate the graphs on this web site. It's fairly fast and quite flexible. I have only tinkered with GD::Graph, but it seems to work fine.

    Depending on how much time you have, try something simple with each package suggested here and see how it fits your brain.

    --t. alex
    but my friends call me T.

Re: Drawing Graphs
by dze27 (Pilgrim) on Sep 12, 2002 at 20:09 UTC
    We had a talk on GD last night at the Ottawa Perl Mongers meeting. You might be interested in a few sample programs.
Re: Drawing Graphs
by PhiRatE (Monk) on Sep 12, 2002 at 23:07 UTC
    There are a few cavets to GD::Graph. The most obvious is the lack of antialiasing, this makes for acceptable web graphics, but not brilliant. For example:

    http://www.summitresources.com.au/shares.htm

    Displays a couple of charts from a custom graphics engine (the basis is actually imlib2), with antialiased lines and a nice semi-transparent underlay.

    http://phirate.exorsus.net/test7.jpeg

    Displays a pretty extreme example, this one generated from perl through povray, I had standard, bar and stacked versions of that engine. Disadvantage is its pretty unreadable for real stats, but it looks nice :)

    So basically you have a number of questions to answer:

    1. Who is the target audience? are they going to require particularly impressive graphics?

    2. Are the graphics for general trend information or precise analysis?

    3. Are the graphics going to be require in realtime? near realtime? any old time?

    4. Do you have a lot of time to muck about with it?

    5. Is there going to be a lot of different composits on any given chart (ie, bars and a min/max/median line etc)?

    Have a think about those, they should point you in the relevant direction in terms of work required. GD is by far the easiest, but you pay for that in terms of simple graphics. Moving to ImLib2 or OpenGL as your rendering basis makes for harder code but a nicer end result (and often faster). Going to povray/rib is really not recommended (from experience :) :)

      I, also, went with the POV-Ray route. I ended up spending a LOT of hours getting the information into a format that was pretty, but still easily readable. This wasn't just a case of reinventing the wheel, this was inventing mining, smelting, and wood working. The fact that POV-Ray takes its instructions from a text source file made it pretty easy to integrate into my final script, but the development time was prohibitive.
      Just my 2 cents.

      Update Posted an example of my code here: POV-Ray graphing example

      oakbox

        PhiRatE or oakbox, is the Perl code you used to generate the POV-Ray scene file for the graphs available somewhere? Being an old POV-Ray fan I'd like to see how you generated the scene file, specifically the camera def...

        (Edit: clarification of request)--Sorry, Beatnik.
        My original, poorly worded question, wonderfully answered by Beatnik was:

        Is the POV-Ray code available somewhere?
        --
        May the Source be with you.

        You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

Re: Drawing Graphs
by toma (Vicar) on Sep 12, 2002 at 23:12 UTC
    If you want extreme accuracy, you should be using a vector graphics format instead of a raster format. This reasoning would lead to using SVG instead of GD::Graph.

    The accuracy of raster graphics is limited by the number of pixels in the graph. With vector graphics, accuracy can be achieved by zooming or rendering on a high-resolution device.

    It should work perfectly the first time! - toma

      SVG also gives you the benefit of XML, you can apply XSLT or what have you to raw XML data. The svg module is excellent and I understand that it can withstand exceptionally heavy server loads.

      SVG also has the benefit of being fully scriptable, and an accepted standard.

      If you make something idiot-proof, eventually someone will make a better idiot.
      I am that better idiot.
Re: Drawing Graphs
by mattr (Curate) on Sep 14, 2002 at 15:25 UTC
    Since nobody mentioned it, graphviz is tres cool. search for it in PM.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://197192]
Approved by RMGir
Front-paged by wil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-03-28 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found