two axis, two data sets GD::Graphic

J

java

Hi, Everybody. I'm trying to set a graphic with two axes and two data
sets for each axis. I'm using GD::Graph. The trouble is: when I load
the graphic (.png), the y2 axis (right) disappear. I don't know what's
happening. Somebody could help? bellow is the code.

#!/usr/bin/perl -w

use GD::Graph::mixed;
@data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 3, 4, 14, 30, 12, 8, 7, 20, 15],
[ 2, 8, 2, 5, 3, 1, 3, 4, 1],
[ 5, 12, 24, 33, 19, 8, 6, 15, 21],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
);

$my_graph = new GD::Graph::mixed( );
$my_graph->set(
x_label => 'X Label',
y1_label => 'Y1 label',
y2_label => 'Y2 label',
title => 'Using two axes',
y1_max_value => 40,
y2_max_value => 8,
y_tick_number => 8,
y_label_skip => 2,
long_ticks => 1,
two_axes => 1,
use_axis => [1,2,1,2],
legend_placement => 'BR',
x_labels_vertical => 1,
x_label_position => 1/2,
);

$my_graph->set_legend( 'X', 'XY', 'diff-X/XY', '95%XY');
my $gd = $my_graph->plot(\@data) or die $my_graph->error;
open(IMG, '>graphTest.gif') or die "Não posso abrir arquivo$!\n";
binmode IMG;
print IMG $gd->gif;
close IMG;
 
Z

zentara

Hi, Everybody. I'm trying to set a graphic with two axes and two data
sets for each axis. I'm using GD::Graph. The trouble is: when I load
the graphic (.png), the y2 axis (right) disappear. I don't know what's
happening. Somebody could help? bellow is the code.

I can offer a clue. if you comment out the 3rd and 4th data set
the y2 axis appears. So I'm guessing the undefined 3rd and 4th
axis labels are overwriting the y2 axis with nothing.
#!/usr/bin/perl -w

use GD::Graph::mixed;
@data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 3, 4, 14, 30, 12, 8, 7, 20, 15],
[ 2, 8, 2, 5, 3, 1, 3, 4, 1],
# [ 5, 12, 24, 33, 19, 8, 6, 15, 21],
# [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],


zentara
 
J

java

zentara escreveu:
Hi, Everybody. I'm trying to set a graphic with two axes and two data
sets for each axis. I'm using GD::Graph. The trouble is: when I load
the graphic (.png), the y2 axis (right) disappear. I don't know what's
happening. Somebody could help? bellow is the code.

I can offer a clue. if you comment out the 3rd and 4th data set
the y2 axis appears. So I'm guessing the undefined 3rd and 4th
axis labels are overwriting the y2 axis with nothing.
#!/usr/bin/perl -w

use GD::Graph::mixed;
@data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 3, 4, 14, 30, 12, 8, 7, 20, 15],
[ 2, 8, 2, 5, 3, 1, 3, 4, 1],
# [ 5, 12, 24, 33, 19, 8, 6, 15, 21],
# [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
But there is an option that permits the 3rd and 4rd definition:
use_axis[1,2,1,2], anyway, I alredy tryied to augment the graphic area
and the problem remain. By the way, do you know another graphic module
that could make the same thing?
 
Z

zentara

and the problem remain. By the way, do you know another graphic module
that could make the same thing?

I'm sure there is one out there, google for
"graph multiple y axis"
"graph multiple y axis perl"

Personally, if I was doing it, I would head straight for the
Tk::Canvas or Tk::Zinc Canvas and make a custom graph.

But those won't work from the commandline, like in a cgi.
Maybe your best bet is to make a couple of separate axis
images and merge them(montage) with the graph?
 
J

java

The trouble with the composition is that I have to write a script that
will do this automatically, because the program that I'm writing
generates many graphics, it may be too dificult to me. Thanks, Zentara,
I will try this search and the TK module.

zentara escreveu:
 
Z

zentara

The trouble with the composition is that I have to write a script that
will do this automatically, because the program that I'm writing
generates many graphics, it may be too dificult to me. Thanks, Zentara,
I will try this search and the TK module.

Tk will let you do this automatically, but the catch is you must have an
X server running. You can start the Tk app minimized, and just let it
run.

If you want a bit of a head start into doing it with Tk,
See: http://perlmonks.org?node_id=577181

Tk may give you a bit of trouble with rotating text labels, but
you can work around that by making a graphic of the label text,
and rotating it into position.

Also consider the Perl/Gtk2 system. It has the ability to
use pango to rotate text, font, colors, etc.
See: http://perlmonks.org?node_id=583578
 
J

java

The Perl/GTK2 seems like appropriated, but I it will take more time to
learn and adaptate it to my script. I started to read your article in
the perl monks. Here is an example of what I need to do:
http://libshuff.mib.uga.edu/XvsY.png, it was done with gnuplot. thanks.



zentara escreveu:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,991
Latest member
Josephnag

Latest Threads

Top