Skip to content

Commit

Permalink
fix plot3d array-ref handling - fix #87
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Apr 13, 2024
1 parent 86001c6 commit ffc111d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -3,6 +3,7 @@
- fixes for Windows (#89)
- use terminal "dumb" if probing shows "unknown" (#66)
- fix numeric-only strings for legend (#100) - thanks @d-lamb for report
- fix plot3d array-ref handling (#87) - thanks @djerius for report

2.024 2023-03-30
- Add Alien::Gnuplot as a configure-time dependency. Fixes #92 - thanks @zmughal
Expand Down
12 changes: 6 additions & 6 deletions lib/PDL/Graphics/Gnuplot.pm
Expand Up @@ -3383,21 +3383,21 @@ PDL::Graphics::Gnuplot. (Set $ENV{'PGG_DEP'}=1 to silence this warning.
}
# Look for the plotStyleProps entry. If not there, try cleaning up the with style
# before giving up entirely.
unless( exists( $plotStyleProps->{$with[0]}->[0] ) ) {
unless ( exists( $plotStyleProps->{$with[0]}[0] ) ) {
our $plotStylesAbbrevs;
# Try pluralizing and lc'ing if that works...
if($with[0] !~ m/s$/i and exists( $plotStyleProps->{lc $with[0].'s'} ) ) {
$with[0] = lc $with[0].'s';
$chunk{options}{'with'}[0] = $with[0];
$chunk{options}{with}[0] = $with[0];
} else {
# nope. throw a fit.
barf "invalid plotstyle 'with ".($with[0])."' in plot\n";
barf "invalid plotstyle 'with $with[0]' in plot\n";
}
}
my $psProps = $plotStyleProps->{$with[0]};
# Extract the data objects from the argument list.
# They should all be either PDLs or array refs.
my @dataPiddles = @args[$argIndex..$nextOptionIdx-1] ;
my @dataPiddles = @args[$argIndex..$nextOptionIdx-1];
# Some plot styles (currently just "fits") are implemented via a
# prefrobnicator that processes the data.
if( $psProps->[ 4 ] ) {
Expand Down Expand Up @@ -3482,7 +3482,7 @@ EOF
##############################
# Implicit dimensions in 3-D plots require imgFlag to be set...
my $cdims = $chunk{options}{cdims} ||
($imgFlag or ( $is3d && $dataPiddles[0]->ndims >= 2 )) ? 2 : 1;
($imgFlag or ( $is3d && $dataPiddles[0]->$_isa('PDL') && $dataPiddles[0]->ndims >= 2 )) ? 2 : 1;
barf("You specified column dimension of 1 for an image plot type! Not allowed.")
if $cdims==1 and $imgFlag;
##############################
Expand All @@ -3493,7 +3493,7 @@ EOF
# The other dimensions have to have at least five elements.
if ( $cdims==2 ) {
if ($chunk{options}{with}[0] eq 'image') {
my $dp = $dataPiddles[$#dataPiddles];
my $dp = $dataPiddles[-1];
if ($dp->ndims==3) {
if ($dp->dim(1) >= 5) {
if ($dp->dim(0) ==3 && $dp->dim(1) >= 5 && $dp->dim(2) >= 5) {
Expand Down
5 changes: 4 additions & 1 deletion t/plot.t
Expand Up @@ -232,11 +232,14 @@ eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),[1,2,3,4,5,6,7,8,9,10])};
is($@, '', "two arguments, second one is an array, works OK");

eval { $w->plot(xmin=>3,xrange=>[4,5],[1,2,3,4,5,6,7,8,9,10],xvals(10))};
is($@, '', "two arguments, second one is an array, works OK");
is($@, '', "two arguments, first one is an array, works OK");

eval { $w->plot([1,2,3,4,5],[6,7,8,9,10]);};
is($@, '', "two arguments, both arrays, works OK");

eval { $w->plot3d([1,2,3,4,5],[6,7,8,9,10],[6,7,8,9,10]);};
is($@, '', "plot3d all arguments are arrays, works OK");

eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),[1,2,3])};
like($@, qr/mismatch/, "Mismatch detected in array size vs. PDL size");

Expand Down

0 comments on commit ffc111d

Please sign in to comment.