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

I'm having some trouble with GD::Graph::lines in trying to reliably display the 2nd Y axis (on the right hand side) so that it consistently aligns with its data.

The curves, I'm pretty sure, are okay. But the tick marks and labels of the 2nd Y axis which should align with those cuves (and with the graph box) along the right hand edge often does not. It may either scrunch toward zero, or bloat out beyond the graphic.

Does anybody have a workaround for this?

TIA,

Gan Uesli Starling
Kalamazoo MI USA

Replies are listed 'Best First'.
Re: GD::Graph::lines with 2 Y Axes
by zentara (Cardinal) on Jul 15, 2006 at 12:52 UTC
    It would help if you showed a simple code example.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: GD::Graph::lines with 2 Y Axes
by aplonis (Pilgrim) on Jul 17, 2006 at 15:30 UTC

    Okay, below is a sample. What is happening only happens when more than two data sets are used. If three or more data sets are used, then the Y2 (right hand) axis labels become offset from the grid such that a label like "100" occurs above or below the 100 grid line.

    Sometimes they are off a little, other times quite a lot. They may be either too scrunched together, or expanded right of the edge of the graphic.

    #!/usr/pkg/bin/perl -w use strict; use Cwd; use GD::Graph::lines; my @foo_y1a; my @foo_y1b; my @foo_y2a; my @foo_y2b; my @foo_x; for (0 .. 99) { push @foo_x, $_; push @foo_y1a, $_ * 1.0 + 10; push @foo_y1b, $_ * 1.1 - 10; push @foo_y2a, $_ * -1.2 + 10; push @foo_y2b, $_ * -1.3 - 10; } my $graph = GD::Graph::lines->new(1024,512); $graph->set_legend('Y1A', 'Y1B', 'Y2A', 'Y2B'); $graph->set_legend_font("GD::gdFontTiny"); # Basic stuff done for all graphs. $graph->set( title => 'TWO AXES PROBLEM', transparent => 0, x_label => 'X DATA', y1_label => 'Y1 DATA', y2_label => 'Y2 DATA', two_axes => 1, use_axis => [1,1,2,2], long_ticks => 1, bgclr => '#c0c0c0', x_labels_vertical => 1, ); my $gd = $graph->plot([\@foo_x, \@foo_y1a, \@foo_y1b, \@foo_y2a, \@foo_y2b]) or print "Oops! Problem: " . $graph->error . " \n"; my $path = cwd() . '/two_axis_problem.png'; open GRAPH, ">$path"; binmode(GRAPH); print GRAPH $gd->png or print "Oops! Problem: $! \n"; ; close GRAPH; # Cause written graph to pop up in viewer. sub graph_display { my $cmd = 'display'; # UNIX default. $cmd = 'imdisplay.exe' if $Config::Config{'osname'} =~ /Win/i; system( qq|start "$cmd" "$cmd"|, qq|"$_[0]"| ) } graph_display($path);