Skip to content

Commit

Permalink
add "polylines" plot type
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Aug 11, 2024
1 parent 45236a0 commit 23d2018
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- add "contours", "fits" plot types
- add "contours", "fits", "polylines" plot types

1.011 2024-04-22
- P{GPLOT,Lplot} to read devices using proper API not subprocesses
Expand Down
16 changes: 16 additions & 0 deletions lib/PDL/Graphics/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,17 @@ height), and optionally a 1-D vector of contour values.
As of 1.012. Displays an image from an ndarray with a FITS header.
Uses C<CUNIT[12]> etc to make X & Y axes including labels.
=item polylines
As of 1.012. Draws polylines, with 2 arguments (C<$xy>, C<$pen>).
The "pen" has value 0 for the last point in that polyline.
use PDL::Transform::Cartography;
use PDL::Graphics::Simple qw(pgswin);
$coast = earth_coast()->glue( 1, scalar graticule(15,1) );
$w = pgswin();
$w->plot(with => 'polylines', $coast->clean_lines);
=item labels
This places text annotations on the plot. It requires three input
Expand Down Expand Up @@ -743,6 +754,7 @@ $plot_options->synonyms( {
});
our $plot_types = {
points => { args=>[1,2], ndims=>[1] },
polylines => { args=>[2], ndims=>[1,2] },
lines => { args=>[1,2], ndims=>[1] },
bins => { args=>[1,2], ndims=>[1] },
circles => { args=>[2,3], ndims=>[1] },
Expand Down Expand Up @@ -958,6 +970,10 @@ sub _translate_plot {
barf "Wrong dims for contours: need 2-D values, 1-D contour values"
unless $args[0]->ndims == 2 and $args[1]->ndims == 1;
($xminmax, $yminmax) = ([0, $args[0]->dim(0)-1], [0, $args[0]->dim(1)-1]);
} elsif ($ptn eq 'polylines') { # not supposed to be compatible
barf "Wrong dims for contours: need 2-D values, 1-D contour values"
unless $args[0]->ndims == 2 and $args[1]->ndims == 1;
($xminmax, $yminmax) = map [$_->minmax], $args[0]->using(0,1);
} else {
# Check that the PDL arguments all agree in a threading sense.
# Since at least one type of args has an array ref in there, we have to
Expand Down
8 changes: 7 additions & 1 deletion lib/PDL/Graphics/Simple/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ our $disp_opts = {
windows=>{persist=>0}
};


##########
# PDL::Graphics::Simple::Gnuplot::check
# Checker
Expand Down Expand Up @@ -271,6 +270,13 @@ our $curve_types = {
}
@out;
},
polylines => sub {
my ($me, $po, $co, $xy, $pen) = @_;
$co->{with} = "lines";
$co->{style} //= 6; # so all polylines have same style, blue somewhat visible against sepia
my $pi = $pen->eq(0)->which;
map [ $co, $_->dog ], path_segs($pi, $xy->mv(0,-1));
},
fits => 'fits',
labels => sub {
my($me, $po, $co, @data) = @_;
Expand Down
1 change: 1 addition & 0 deletions lib/PDL/Graphics/Simple/PGPLOT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ sub new {
}

our $pgplot_methods = {
polylines => 'lines',
'lines' => 'line',
'bins' => 'bin',
'points' => 'points',
Expand Down
8 changes: 8 additions & 0 deletions lib/PDL/Graphics/Simple/PLplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ our $plplot_methods = {
my $dy = ($data->[1]->flat->slice("*1") + $dr->slice("*1") * $s)->flat;
$me->{obj}->xyplot( $dx, $dy, PLOTTYPE=>'LINE',%{$ppo});
},
polylines => sub {
require PDL::ImageND;
my ($me,$ipo,$data,$ppo) = @_;
my ($xy, $pen) = @$data;
my $pi = $pen->eq(0)->which;
$me->{obj}->xyplot($_->dog, PLOTTYPE=>'LINE', %$ppo)
for PDL::ImageND::path_segs($pi, $xy->mv(0,-1));
},
labels => sub {
my ($me, $ipo, $data, $ppo) = @_;

Expand Down
9 changes: 9 additions & 0 deletions lib/PDL/Graphics/Simple/Prima.pm
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ sub _load_types {
}
},

polylines => sub {
my ($me, $plot, $block, $cprops) = @_;
my ($xy, $pen) = @$block;
my $pi = $pen->eq(0)->which;
$plot->dataSets()->{ 1+keys(%{$plot->dataSets()}) } =
ds::Pair($_->dog, plotType=>ppair::Lines(), @$cprops)
for path_segs($pi, $xy->mv(0,-1));
},

image => sub {
my ($me, $plot, $data, $cprops, $co, $ipo) = @_;
my ($xmin, $xmax) = $data->[0]->minmax;
Expand Down

0 comments on commit 23d2018

Please sign in to comment.