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

Hi, Monks!

I need to plot several data sets on the chart which uses two separate axes (for different data sets). Here you can find example of such plot.

I'm using DBD::Chart but with no luck (here you can find my chart) :-( Also i see in GD::Graph two_axes option but it can be used only with two data sets.

How i can create second vertical axis on my graph and use it for some data sets?

  • Comment on Plot several data set on two separate axes

Replies are listed 'Best First'.
Re: Plot several data set on two separate axes
by moritz (Cardinal) on Apr 15, 2010 at 09:40 UTC
    You could try Chart::Clicker, which looks very flexible to me (though I've never used it myself).

    I'm also sure that gnuplot can do it. Gnuplot reads plotting instructions from a text file, and data from comma or whitespace separated files, both are pretty easy to generate with Perl.

    Perl 6 - links to (nearly) everything that is Perl 6.
      Gnuplot happily reads both plotting instructions and data from stdin, allowing you to just open a pipe to gnuplot and generate plots without having to create intermediate files.

        I haven't used them, but there are even (Perl) programs that are geared towards driving gnuplot for streaming data:

Re: Plot several data set on two separate axes
by BrowserUk (Patriarch) on Apr 15, 2010 at 13:53 UTC
    Also i see in GD::Graph two_axes option but it can be used only with two data sets

    Not so. From the GD::Graph docs:

    two_axes

    Use two separate axes for the first and second data set. The first data set will be set against the left axis, the second against the right axis. If more than two data sets are being plotted, the use_axis option should be used to specify which data sets use which axis.

    Note that if you use this option, that you need to use y1_label and y2_label, instead of just y_label, if you want the two axes to have different labels. The same goes for some other options starting with the letter 'y' and an underscore.

    Default: 0.

    use_axis

    If two y-axes are in use and more than two datasets are specified, set this option to an array reference containing a value of 1 or 2 (for the left and right scales respectively) for each dataset being plotted. That is, to plot three datasets with the second on a different scale than the first and third, set this to [1,2,1]<.

    Default: [1,2].

    An example:

    #! perl -slw use strict; use GD::Graph::lines; my @data = ( [ 1 .. 10 ], [ map{ -5 + int rand 40 } 1 .. 10 ], [ map{ -5000 + int rand 7000 } 1 .. 10 ], [ map{ -5 + int rand 40 } 1 .. 10 ], [ map{ -5000 + int rand 7000 } 1 .. 10 ], ); my $graph = GD::Graph::lines->new( 1000, 600 ); $graph->set( two_axes => 1, use_axis => [ 1,2,1,2 ], ); my $gd = $graph->plot( \@data ) or die $graph->error; open IMG, '>:raw', 'multiline.png' or die $!; print IMG $gd->png; close IMG; system 'multiline.png';

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It is still not representing the 2nd and 4th datasets on other y-axis. I couldn't see the second y axis appearing on the right.
        It is still not representing the 2nd and 4th datasets on other y-axis.

        Really.

        I couldn't see the second y axis appearing on the right.

        What do you see?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
        In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit