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

Dear PerlMonks

What must I do to get Chart::Gnuplot to plot two different Y variables vs X on one chart?

My two Y variables are:-
Y1 NFrogs, with values between zero and 400.
Y2 AirTemperature, with values between -10 and 25.
Variable X Time runs from 1 February to 28 April, with one value per day for NFrogs, 1 value every 20 minutes for Temperature.

So I set  yrange => [0,400], # Numbers of frogs crossing the road each evening

And  y2range => [-5,20], # Air temperatures by http://api.wunderground.com

Then with  $chart->plot2d( $Frogs, $Temperatures)
I get a graph of two variables, NFrogs and Temperatures, vs Date. But both NFrogs and Temperatures are plotted on a scale of 0 to 400.

The other way round i.e.  $chart->plot2d($Temperatures, $Frogs)
this time, NFrogs and Temperatures are both plotted on a scale of -10 to 25.

How do I get each Y variable plotted on its own scale?

http://www.gnuplot.info/faq says
(Q.) 4.7 Does gnuplot support multiple y-axes on a single plot?
(A.) Yes. You can have 2 x- and 2 y-axes per plot. The additional axes are called x2 and y2.

But I cant find an example of this at CPAN's Gnuplot Examples

RichardH

Replies are listed 'Best First'.
Re: Chart::Gnuplot Frogs and Temperatures vs date
by VinsWorldcom (Prior) on Oct 15, 2014 at 14:44 UTC
Re: Chart::Gnuplot Frogs and Temperatures vs date
by VinsWorldcom (Prior) on Oct 16, 2014 at 00:59 UTC

    You need to specify the axes to plot against in the dataset object. Having no idea what your code or data looks like, the following example should help. Note, I'm on Windows 7 x64 / Strawberry 5.18.1 MSWin32-x64-multi-thread, so the 'gnuplot' and 'terminal' arguments are required to the chart object to get it to work.

    use strict; use warnings; use Chart::Gnuplot; my $chart = Chart::Gnuplot->new( gnuplot => 'C:\usr\bin\gnuplot.bat', terminal => 'wxt', yrange => [0,5], ylabel => 'Primary 1-4', y2range => [0,50], y2label => 'Secondary 10-40', y2tics => [0, 10, 20, 30, 40, 50] ); my $dataset1 = Chart::Gnuplot::DataSet->new( ydata => [1,2,3,4] ); my $dataset2 = Chart::Gnuplot::DataSet->new( ydata => [11,21,31,41], axes => 'x1y2' ); $chart->plot2d($dataset1, $dataset2);
Re: Chart::Gnuplot Frogs and Temperatures vs date
by RCH (Sexton) on Oct 16, 2014 at 07:38 UTC

    Thank you for quick reply - yes, adding axes like this

    my $datasetTemps = Chart::Gnuplot::DataSet->new( title => "Dry bulb temperature", axes => "x1y1", ... ...

    and

    my $datasetFrogs = Chart::Gnuplot::DataSet->new( title => "Number of Frogs per day", axes => "x1y2",

    works purrfectly
    Richard H