package PDL::Graphics::Prima::Simple;
use strict;
use warnings;
use Carp 'croak';
our $VERSION = 0.17; # update with update-version.pl
use PDL::Graphics::Prima;
=head1 NAME
PDL::Graphics::Prima::Simple - a very simple plotting interface for
PDL::Graphics::Prima
=head1 SYNOPSIS
use PDL::Graphics::Prima::Simple;
use PDL;
# --( Super simple line and symbol plots )--
# Generate some data - a sine curve
my $x = sequence(100) / 20;
my $y = sin($x);
# Draw x/y pairs. Default x-value are sequential:
line_plot($y); line_plot($x, $y);
circle_plot($y); circle_plot($x, $y);
triangle_plot($y); triangle_plot($x, $y);
square_plot($y); square_plot($x, $y);
diamond_plot($y); diamond_plot($x, $y);
X_plot($y); X_plot($x, $y);
cross_plot($y); cross_plot($x, $y);
asterisk_plot($y); asterisk_plot($x, $y);
# Sketch the sine function for x initially from 0 to 10:
func_plot(0 => 10, \&PDL::sin);
# --( Super simple histogram )--
# Plot a distribution
hist_plot($distribution);
# Tweak the binning
hist_plot($distribution, bt::Linear(normalize => 0));
# --( Super simple matrix plots )--
# Generate some data - a wavy pattern
my $image = sin(sequence(100)/10)
+ sin(sequence(100)/20)->transpose;
# Generate a grayscale image:
matrix_plot($image); # smallest is white
imag_plot($image); # smallest is black
# Set the x and y coordinates for the image boundaries
# left, right, bottom, top
matrix_plot([ 0, 1 ], [ 0, 2 ], $image);
imag_plot( [ 0, 1 ], [ 0, 2 ], $image);
# --( More complex plots )--
# Use the more general 'plot' function for
# multiple DataSets and more plotting features:
my $colors = pal::Rainbow()->apply($x);
plot(
-lines => ds::Pair($x, $y
, plotType => ppair::Lines
),
-color_squares => ds::Pair($x, $y + 1
, colors => $colors,
, plotType => ppair::Squares(filled => 1)
),
x => { label => 'Time' },
y => { label => 'Sine' },
);
# --( Managing window interaction )--
# In scripts and older Term::ReadLine, if you press
# the letter 'q' when viewing a plot, you can
# re-invoke interaction with:
twiddle;
# query auto-twiddling
my $is_auto_twiddline = auto_twiddle;
# Turn auto-twiddling on or off
auto_twiddle(1);
auto_twiddle(0);
=head1 DESCRIPTION
One of Perl's mottos is to "make easy things easy, and hard things possible."
The bulk of the modules provided by the
L distribution
focus on the latter half, making hard but very powerful things possible.
This module tackles the other half: making easy things easy. This module
provides a number of simple functions for quick data plotting so that you can
easily get a first look at your data. You can think of this as providing a
function-based interface to plotting, in contrast to the GUI/OO interface of
the rest of L. Or you
can look at this as providing a handy collection of plot (and window)
constructors for the standard use cases. Either perspective is basically correct.
In addition to making easy plots easy, this module and its documentation are
meant to serve as an introduction to L.
If you are new to the libarary, this is where you should start.
This module is built on L and
L. You do not need to know much about
L to use this tutorial, but you should know
L.
When you use this library, you get a handful of functions for quick data
plotting that include
=over
=item lines
L takes one or two Ls, one for y and optionally one for
x, and makes a L with
them; if you don't give an x L, it uses
L.
=item symbols
Various symbol plots, like L and
L, take one or two Ls, one
for y and optionally one for
x, and and plots the L
at the given points; if you don't give an x L, it uses
L.
=item functions
L takes an I plot min/max and a L and
makes a L of the
L; it can optionally take the number of points to evaluate
on each drawing operation; see L
=item histograms
L takes a L of data to be plotted and an optional
L and plots a
L. If no bin
type is supplied, L
is used.
=item images
Both L and L take one or
three arguments, the first two of which specify the x-bounds and the
y-bounds, the third (or only) of which is the matrix to plot
=item plot (...)
L is a much more powerful routine that takes the same
arguments you would pass to
the constructor of a L, and packs the
resulting plot widget in a L.
=back
And with that, let's look at how to I