two axis, two data sets GD::Graphic

Discussion in 'Perl Misc' started by java, Dec 4, 2006.

  1. java

    java Guest

    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;
    java, Dec 4, 2006
    #1
    1. Advertising

  2. java

    zentara Guest

    On 4 Dec 2006 10:36:59 -0800, "java" <> wrote:

    >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

    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    zentara, Dec 5, 2006
    #2
    1. Advertising

  3. java

    java Guest

    zentara escreveu:

    > On 4 Dec 2006 10:36:59 -0800, "java" <> wrote:
    >
    > >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?
    java, Dec 6, 2006
    #3
  4. java

    zentara Guest

    On 6 Dec 2006 03:57:53 -0800, "java" <> wrote:


    >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?



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    zentara, Dec 6, 2006
    #4
  5. java

    java Guest

    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:
    > On 6 Dec 2006 03:57:53 -0800, "java" <> wrote:
    >
    >
    > >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?
    >
    >
    >
    > --
    > I'm not really a human, but I play one on earth.
    > http://zentara.net/japh.html
    java, Dec 6, 2006
    #5
  6. java

    zentara Guest

    On 6 Dec 2006 07:28:55 -0800, "java" <> wrote:

    >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



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    zentara, Dec 7, 2006
    #6
  7. java

    Dr.Ruud Guest

    zentara schreef:

    > google for
    > "graph multiple y axis"
    > "graph multiple y axis perl"


    Last time I did this, I ended up using PHP's PEAR::Image_Graph
    http://pear.veggerby.dk/samples/ (look for "secondary")

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Dec 7, 2006
    #7
  8. java

    java Guest

    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:

    > On 6 Dec 2006 07:28:55 -0800, "java" <> wrote:
    >
    > >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
    >
    >
    >
    > --
    > I'm not really a human, but I play one on earth.
    > http://zentara.net/japh.html
    java, Dec 8, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page