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

Hi All,

I've been trying to find a graphing package that can generate a graph of non uniform points that have bars/lines down to the x axis.
Below is an example with real data using the Chart::Plot package, the resulting graph has the points marked. Do any of you know off a package that has an option to do this. You get a bonus point if it works on a win32 machine. I've looked at the GD::Graph package and the DBD::Chart::Plot (no easy install by ActiveState perl, its possible that the candlestick feature may work if the ymin vales are all set to 0 and the max values to the y value) as well but neither of them seem to do what I want right of the bat.

An alternative would be to create a graph and then modify the graphic image but I'm looking for an easier method if there is one.

Richard

#!/usr/bin/perl -w use GD::Graph::lines; #my @xdataset = qw(791.312 809.298 825.259 842.510 855.028 861.120 870 +.554 870.977 877.036 893.436 1060.006 1066.030 1081.967 1270.989 2211 +.105 2225.178 2239.090); #my @ydataset = qw(1383.8 1863.9 1247 2191.4 2101.2 624.96 552.55 10 +50.3 690.71 538.11 705.84 566.41 397.68 133.13 158.5 91.587 82.42); @data = ( ["100","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 100, 200, 500, 600, 300, 150, 101, 301, + 401], [ sort { $a <=> $b } (105, 205, 505, 605, 305, 155, 106, 306, 406) +] ); my $graph = GD::Graph::lines->new(400, 300); $graph->set( x_label => 'Day', y_label => 'No. Attacks', title => 'Number of Worm attacks per day by type', y_max_value => 8, y_tick_number => 1, y_label_skip => 2 ); my $gd = $graph->plot(\@data); #chdir "d:"; #chdir "d:/http/Pics"; open(IMG, '>days.png') or die $!; binmode IMG; print IMG $gd->png;

Replies are listed 'Best First'.
Re: Graphing non uniform data as bar charts
by lostcause (Monk) on Aug 15, 2001 at 07:35 UTC
    Oh woe is me. I pasted the wrong code example in the message. This is what should have been there:
    #!/usr/bin/perl -w use Chart::Plot; use strict; my $img = Chart::Plot->new(); my @xdataset = qw(791.312 809.298 825.259 842.510 855.028 861.120 870. +554 870.977 877.036 893.436 1060.006 1066.030 1081.967 1270.989 2211. +105 2225.178 2239.090); my @ydataset = qw(1383.8 1863.9 1247 2191.4 2101.2 624.96 552.55 105 +0.3 690.71 538.11 705.84 566.41 397.68 133.13 158.5 91.587 82.42); $img->setData (\@xdataset, \@ydataset, 'nolines points'); $img->setGraphOptions ('horGraphOffset' => 75, 'vertGraphOffset' => 100, 'title' => 'Mass Spectrum', 'horAxisLabel' => 'mass/charge', 'vertAxisLabel' => 'intensity' ); open (WR,'>plot.png') or die ("Failed to write file: $!"); binmode WR; # for DOSish platforms print WR $img->draw(); close WR;

    Sorry to waste your time once again. R

Re: Graphing non uniform data as bar charts
by Albannach (Monsignor) on Aug 15, 2001 at 20:57 UTC
    As Chart::Plot is still rather simple I think you will need to graph then modify the image, but fortunately that is rather easy to do as you have complete access to the underlying GD object. Of course this will work just fine in Win32 (that's where I tested it).

    There is one more glitch however - Chart::Plot does not correctly account for the plotting offset caused by insertion of the graph title, so you cannot use that option if you want this to work. You may just superimpose the graph title text via the GD object, I didn't bother for this trial. I hope this helps!

    #!/usr/bin/perl -w use strict; use Chart::Plot; my $img = Chart::Plot->new(); my @xdataset = qw(791.312 809.298 825.259 842.510 855.028 861.120 870.554 870.977 877.036 893.436 1060.006 1066.030 1081.967 1270.989 2211.105 2225.178 2239.090); my @ydataset = qw(1383.8 1863.9 1247 2191.4 2101.2 624.96 552.55 1050.3 690.71 538.11 705.84 566.41 397.68 133.13 158.5 91.587 82.42); $img->setGraphOptions ( 'horGraphOffset' => 75, 'vertGraphOffset' => 100, 'horAxisLabel' => 'mass/charge', 'vertAxisLabel' => 'intensity', ); # plots nothing visible, but sets up axis scales: $img->setData (\@xdataset, \@ydataset, 'nolines nopoints'); # now draw some vertical bars: my $gdobj = $img->getGDobject; my $blue = $gdobj->colorAllocate(0,0,255); for my $i (0..$#xdataset) { $gdobj->line($img->data2pxl($xdataset[$i],0), $img->data2pxl($xdataset[$i], $ydataset[$i]), $blue); } open (WR,'>plot.png') or die ("Failed to write file: $!"); binmode WR; # for DOSish platforms print WR $img->draw(); close WR;

    --
    I'd like to be able to assign to an luser

      Thanks Albannach,
      That's a perfect solution. Fortunately a graph title is not necessary. I plan
      to plot multiple data sets on to the same graph which will be given to collaborators
      as a basic report. I need to make a second graph to show the error of the measurements,
      which should be fairly simple and then roll them up into a document either html,
      word or maybe even xml.
      I still have someway to go.