Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

GD::graph: layout Question.

by Excentis_Perl (Initiate)
on Aug 06, 2007 at 11:54 UTC ( #630798=perlquestion: print w/ replies, xml ) Need Help??
Excentis_Perl has asked for the wisdom of the Perl Monks concerning the following question:


I'm using the GD::Graph module to automatically create line graphs.
But I can't seem to find an option to start the line at the Y-axis. There's always a gap of one unit, which results in poor looking graphs if it's a graph with little data.

(f.e. poor graph, code)

and cuz looks are everything I would like to solve this. Am I overlooking some simple option or can you help me with a short workaround?

Much appreciated.

Comment on GD::graph: layout Question.
Re: GD::graph: layout Question.
by zentara (Archbishop) on Aug 06, 2007 at 12:32 UTC
      Thx for the fast reply, it's the same problem indeed, but unanswered for my use, don't wanne use bars for the application.
      I think there's no direct option in the module to do shift the line to the edge...
        Well the last reply in that node DID get the axis to shift to 0.
        #!/usr/bin/perl use warnings; use strict; use GD::Graph::lines; # See: use constant PI => 4 * atan2(1,1); print STDERR "Processing sample55\n"; my @x = map {$_ * 3 * PI/100} (0 .. 100); my @y = map sin, @x; my @z = map cos, @x; my @data = (\@x,\@y,\@z); my $my_graph = new GD::Graph::lines(400,400); $my_graph->set( x_label => 'Angle (Radians)', y_label => 'Trig Function Value', x_tick_number => 'auto', y_tick_number => 'auto', title => 'Sine and Cosine', line_width => 1, x_label_position => 1/2, r_margin => 15, transparent => 0, ); $my_graph->set_legend('Thanks to Scott Prahl'); my $gd = $my_graph->plot(\@data); open (IMG, ">$0.png") or die $!; binmode IMG; print IMG $gd->png; close IMG;
        However, I tried to put your data into the exact same script, and it wouldn't go to 0...... I think GD::Graph::lines is buggy about this. I tried mapping your data, tried changing your text axis marks to numeric... (0,1,2,3).... and it still wouldn't shift. Very aggravating.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: GD::graph: layout Question.
by cLive ;-) (Parson) on Aug 06, 2007 at 14:12 UTC
    GD::Graph::Lines can be a bitch sometimes. I played with it a while back. Perhaps you'll find this example useful? (scroll down for links to scripts).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://630798]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-08-28 03:17 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (255 votes), past polls