PDL-Graphics-Simple

 view release on metacpan or  search on metacpan

lib/PDL/Graphics/Simple.pm  view on Meta::CPAN

 hold;
 line($x, sqrt($y)*10);
 release;


=item * Justify aspect ratio

 imag $im, {justify=>1}
 points($x, $y, {justify=>1});

=item * Erase/delete the plot window

 erase();

=back

=head2 Simple object-oriented plotting

More functionality is accessible through direct use of the PDL::Graphics::Simple
object.  You can set plot size, direct plots to files, and set up multi-panel plots.

The constructor accepts window configuration options that set the plotting
environment, including size, driving plot engine, output, and multiple
panels in a single window.

For interactive/display plots, the plot is rendered immediately, and lasts until
the object is destroyed.  For file plots, the file is not guaranteed to exist
and be correct until the object is destroyed.

The basic plotting method is C<plot>.  C<plot> accepts a collection of
arguments that describe one or more "curves" (or datasets) to plot,
followed by an optional plot option hash that affects the entire plot.
Overplotting is implemented via plot option, via a held/released state
(as in PGPLOT), and via a convenience method C<oplot> that causes the
current plot to be overplotted on the previous one.

Plot style (line/points/bins/etc.) is selected via the C<with> curve option.
Several convenience methods exist to create plots in the various styles.

=over 3

=item * Load module and create basic objects

 use PDL::Graphics::Simple;
 $x = xvals(51)/5;
 $y = $x**3;

 $win = pgswin();                       # plot to a default-shape window
 $win = pgswin( size=>[4,3] );          # size is given in inches by default
 $win = pgswin( size=>[10,5,'cm'] );    # You can feed in other units too
 $win = pgswin( out=>'plot.ps' );       # Plot to a file (type is via suffix)
 $win = pgswin( engine=>'gnuplot' );    # Pick a particular plotting engine
 $win = pgswin( multi=>[2,2] );         # Set up for a 2x2 4-panel plot

=item * Simple plots with C<plot>

 $win->plot( with=>'line', $x, $y, {title=>"Simple line plot"} );
 $win->plot( with=>'errorbars', $x, $y, sqrt($y), {title=>"Error bars"} );
 $win->plot( with=>'circles', $x, $y, sin($x)**2 );

=item * Plot overlays

 # All at once
 $win->plot( with=>'line', $x, $y,   with=>'circles', $x, $y/2, sqrt($y)  );

 # Using oplot (IDL-style; PLplot-style)
 $win->plot(  with=>'line', $x, $y );
 $win->oplot( with=>'circles', $x, $y/2, sqrt($y) );

 # Using object state (PGPLOT-style)
 $win->line(  $x, $y );
 $win->hold;
 $win->circles( $x, $y/2, sqrt($y) );
 $win->release;

=back


=head1 FUNCTIONS

=cut

package PDL::Graphics::Simple;

use strict;
use warnings;
use PDL;
use PDL::Options q/iparse/;
use File::Temp qw/tempfile tempdir/;
use Scalar::Util q/looks_like_number/;

our $VERSION = '1.016';
$VERSION =~ s/_//g;

##############################
# Exporting
use base 'Exporter';
our @EXPORT = qw(pgswin line points bins imag cont hold release erase);
our @EXPORT_OK = (@EXPORT, qw(image plot));

our $API_VERSION = '1.012'; # PGS version where that API started

##############################
# Configuration

# Knowledge base containing found info about each possible backend
our $mods = {};
our $mod_abbrevs = undef;
our $last_successful_type = undef;
our $global_plot = undef;

# lifted from PDL::Demos::list
sub _list_submods {
  my @d = @_;
  my @found;
  my %found_already;
  foreach my $path ( @INC ) {
    next if !-d (my $dir = File::Spec->catdir( $path, @d ));
    my @c = do { opendir my $dirfh, $dir or die "$dir: $!"; grep !/^\./, readdir $dirfh };
    for my $f (grep /\.pm$/ && -f File::Spec->catfile( $dir, $_ ), @c) {
      $f =~ s/\.pm//;



( run in 1.279 second using v1.01-cache-2.11-cpan-39bf76dae61 )