Sorry, here's an example:
use Chart::Gnuplot;
my @charts;
for my $metric ( qw(metric1 metric2 metric3 metric4 metric5 metric6 metric7 metric8 metric9) ) {
my $chart = Chart::Gnuplot->new(
title => $metric,
xtics => { rotate => -90 },
);
my $data = Chart::Gnuplot::DataSet->new(
xdata => [ 1..10 ],
ydata => [ map { rand() } 1..10 ],
style => 'linespoints',
);
$chart->add2d($data);
push @charts, $chart;
}
my $chart = Chart::Gnuplot->new(
output => 'multiplot.pdf',
terminal => 'pdfcairo',
);
$chart->multiplot(@charts);
The above will produce 9 plots overlapped on the same page of the PDF (same thing happens if the terminal is postscript).
Adding the following workaround (hack) e.g. before the for loop:
*Chart::Gnuplot::_setMultiplot = sub { 1 };
...enables the above code to generate a 9-page PDF, one plot per page. :)
Essentially the multiplot directive should not be issued unless $charts[0] is an array ref.
Arguably `sub multiplot` could be made even more generic by iterating over @charts and checking whether each individual @chart item is an arrayref or not, to support a mix of multi-page and multi-plot-per-page, e.g. with the below patch:
*** Chart/Gnuplot.pm.orig 2013-04-21 03:11:52.000000000 -0400
--- Chart/Gnuplot.pm 2014-04-22 09:58:21.325306500 -0400
***************
*** 149,165 ****
"center offset 0,-1\n";
}
! if (scalar(@charts) == 1 && ref($charts[0]) eq 'ARRAY')
{
! my $nrows = scalar(@{$charts[0]});
! my $ncols = scalar(@{$charts[0][0]});
&_setMultiplot($self, $nrows, $ncols);
for (my $r = 0; $r < $nrows; $r++)
{
for (my $c = 0; $c < $ncols; $c++)
{
! my $chart = $charts[0][$r][$c];
$chart->_script($self->{_script});
$chart->_multiplot(1);
delete $chart->{bg};
--- 149,167 ----
"center offset 0,-1\n";
}
! foreach my $chart (@charts)
! {
! if (ref($chart) eq 'ARRAY')
{
! my $nrows = scalar(@$chart);
! my $ncols = scalar(@{$chart->[0]});
&_setMultiplot($self, $nrows, $ncols);
for (my $r = 0; $r < $nrows; $r++)
{
for (my $c = 0; $c < $ncols; $c++)
{
! my $chart = $chart->[$r][$c];
$chart->_script($self->{_script});
$chart->_multiplot(1);
delete $chart->{bg};
***************
*** 186,199 ****
&_reset($chart);
}
}
}
else
{
- # Start multi-plot
- &_setMultiplot($self);
-
- foreach my $chart (@charts)
- {
$chart->_script($self->{_script});
$chart->_multiplot(1);
delete $chart->{bg};
--- 188,197 ----
&_reset($chart);
}
}
+ _unsetMultiplot($self);
}
else
{
$chart->_script($self->{_script});
$chart->_multiplot(1);
delete $chart->{bg};
***************
*** 939,944 ****
--- 937,952 ----
print PLT "\n";
close(PLT);
}
+
+ sub _unsetMultiplot
+ {
+ my ($self) = @_;
+
+ open(PLT, ">>$self->{_script}") || confess("Can't write $self->{_script}");
+ print PLT "unset multiplot";
+ print PLT "\n";
+ close(PLT);
+ }
...then the following modification to the example code (*without* the _setMultiplot override hack) works as expected:
$chart->multiplot(@charts[0..3], [ [@charts[0..2]], [@charts[3..5]], [@charts[6..8]] ], @charts[4..8]);3
...and will produce a 10-page pdf, where pages 1-4 and 6-10 contain one chart per page, and where page 5 contains a 3x3 matrix of charts.
Cheers,
V.
From: kwmak@cpan.org
Date: Mon, 21 Apr 2014 13:12:44 +0800
Subject: Re: [rt.cpan.org #94867] Can't plot multiple charts over multiple pages
To: bug-Chart-Gnuplot@rt.cpan.org; ntvdm@hotmail.com
Hi,
Could you please show me an example of the output (one chart per page)?
2014-04-19 4:03 GMT+08:00
https://www.google.com/accounts/o8/id?id=AItOawlTGdLkGuFO1capRNVGwhAasU4qs_MxBvQ via RT <bug-Chart-Gnuplot@rt.cpan.org>:
Fri Apr 18 16:03:11 2014: Request 94867 was acted upon.
Transaction: Ticket created by
https://www.google.com/accounts/o8/id?id=AItOawlTGdLkGuFO1capRNVGwhAasU4qs_MxBvQ
Queue: Chart-Gnuplot
Subject: Can't plot multiple charts over multiple pages
Broken in: (no value)
Severity: (no value)
Owner: Nobody
Requestors: ntvdm@hotmail.com
Status: new
Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=94867>
There should be a way to use a multiplot()-like plot function (or multiplot itself) that does not issue "set multiplot" in order to be able to print several charts, one chart per page.