Skip to content

Commit

Permalink
add multiplot_next to skip one plot - fix #85
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Apr 13, 2024
1 parent 240b110 commit 7c1df16
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- fix numeric-only strings for legend (#100) - thanks @d-lamb for report
- fix plot3d array-ref handling (#87) - thanks @djerius for report
- fix gplot array-ref handling (#86) - thanks @djerius for report
- add multiplot_next to skip one plot (#85)

2.024 2023-03-30
- Add Alien::Gnuplot as a configure-time dependency. Fixes #92 - thanks @zmughal
Expand Down
47 changes: 38 additions & 9 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,7 @@ sub fits {
$w->multiplot(layout=>[2,2,"columnsfirst"]);
$w->plot({title=>"points"},with=>"points",$a,$b);
$w->plot({title=>"lines"}, with=>"lines", $a,$b);
$w->multiplot_next; # with Gnuplot 4.7+
$w->plot({title=>"image"}, with=>"image", $a->(*1) * $b );
$w->end_multi();
Expand Down Expand Up @@ -3963,6 +3964,12 @@ of each plot within the grid.
=back
=head2 multiplot_next
=for ref
Skip one plot. Added in 2.025. Requires Gnuplot 4.7+.
=head2 end_multi
=for usage
Expand Down Expand Up @@ -4065,23 +4072,45 @@ sub multiplot {
return;
}

sub multiplot_next {
barf "multiplot_next: need Gnuplot 4.7+\n"
if $PDL::Graphics::Gnuplot::gp_version < 4.7;
my $this = _obj_or_global(\@_);
barf "multiplot_next: you can't, you're not in multiplot mode\n"
unless $this->{options}{multiplot};
my $checkpointMessage;
if ($check_syntax) {
_printGnuplotPipe($this, "syntax", "set multiplot next\n");
$checkpointMessage = _checkpoint($this, "syntax");
barf "Gnuplot error: set multiplot next failed on syntax check!\n$checkpointMessage"
if $checkpointMessage;
}
_printGnuplotPipe($this, "main", "set multiplot next\n");
$checkpointMessage = _checkpoint($this, "main");
if ($checkpointMessage) {
if ($MS_io_braindamage) {
carp "WARNING: unexpected chatter after set multiplot next:\n$checkpointMessage\n";
} else {
barf("Gnuplot error: set multiplot next failed!\n$checkpointMessage");
}
}
}

sub end_multi {
my $this = _obj_or_global(\@_);
unless($this->{options}{multiplot}) {
barf("end_multi: you can't, you're not in multiplot mode\n");
}
barf "end_multi: you can't, you're not in multiplot mode\n"
unless $this->{options}{multiplot};
my $checkpointMessage;
if($check_syntax){
if ($check_syntax) {
_printGnuplotPipe( $this, "syntax", "unset multiplot\n");
$checkpointMessage = _checkpoint($this, "syntax");
if($checkpointMessage) {
barf("Gnuplot error: unset multiplot failed on syntax check!\n$checkpointMessage");
}
barf "Gnuplot error: unset multiplot failed on syntax check!\n$checkpointMessage"
if $checkpointMessage;
}
_printGnuplotPipe($this, "main", "unset multiplot\n");
$checkpointMessage = _checkpoint($this, "main");
if($checkpointMessage) {
if($MS_io_braindamage) {
if ($checkpointMessage) {
if ($MS_io_braindamage) {
carp "WARNING: unexpected chatter after unset multiplot:\n$checkpointMessage\n";
} else {
barf("Gnuplot error: unset multiplot failed!\n$checkpointMessage");
Expand Down
11 changes: 11 additions & 0 deletions t/plot.t
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ unlink($testoutput) or warn "\$!: $! for '$testoutput'";
is 0+@lines, 1, "xlabel gets reset on multiplots";
}

if ($PDL::Graphics::Gnuplot::gp_version >= 4.7) { # only 4.7+
$w = gpwin('dumb',size=>[79,24,'ch'], output=>$testoutput);
$w->multiplot(layout=>[1,2]);
$w->line(xvals(5)**2,{xlabel=>"FOO BAR BAZ"});
$w->multiplot_next;
$w->end_multi;
undef $w;
my @lines = grep m/FOO BAR BAZ/, do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
is 0+@lines, 1, "xlabel gets reset on multiplots";
}

##############################
# Test ascii data transfer (binary is tested by default on platforms where it works)
eval {$w = gpwin('dumb', size=>[79,24,'ch'],output=>$testoutput);};
Expand Down

0 comments on commit 7c1df16

Please sign in to comment.