2. Introduction
PDL and PLplot
PLplot
PDL Bindings
Alternatives
First Steps
Multiple Curves
Boxes and Viewports
Other Methods Introduction
Text
Using the mem
Device
Miscellaneous
Conclusions
3. PDL and PLplot
Introduction
PDL and PLplot
The Perl Data Language, PLplot, a modern open-source
PLplot making number-crunching as plotting library written in C.
PDL Bindings
Alternatives
easy as writing a Perl script.
First Steps
Multiple Curves pdl.perl.org plplot.sourceforge.net
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
4. PLplot
Introduction
PDL and PLplot s Written in C
PLplot
PDL Bindings
Alternatives
s Bindings for Lisp, Perl (PDL), Python, OCaml, etc
First Steps
s Strong separation between plotting commands and output
Multiple Curves
Boxes and Viewports
devices
Other Methods
s All plotting commands can be used on all output devices
Text
Using the mem
Device s New devices are relatively easy to write - only require a
Miscellaneous handful of commands
Conclusions
s Well documented with many examples on their website
s Downside: worked very hard on cross-platform
compatibility, but installation is still tricky sometimes
5. PDL::Graphics::PLplot
Introduction
PDL and PLplot
High-level object-oriented in- Low-level wrappers of (most
PLplot terface of) the C interface
PDL Bindings
Alternatives
s Easier s More powerful
First Steps
Multiple Curves
s Perlish feel s Feels like C
Boxes and Viewports
Other Methods s Only a handful of func- s Many functions
Text tions
Using the mem
Device s Tweak plots by calling
Miscellaneous
s Tweak plots by specifying tweaking functions
Conclusions
options
s Incomplete
6. Alternatives
Introduction
PDL and PLplot
Alternatives to using PLplot:
PLplot
PDL Bindings
Alternatives
s PGPLOT (requires Fortran to compile)
First Steps
s Asymptote, with Perl and PDL bindings (slow)
Multiple Curves
Boxes and Viewports s gnuplot (no PDL interface)
Other Methods
Text s PDL::Graphics::TriD (not publication quality)
Using the mem
Device
s Karma ??
Miscellaneous
Conclusions
s ... and many others
7. Introduction
First Steps
Loading PLplot
Hello PLplot
Labels and Title
Setting the Device
Plotting Points
Multiple Curves
Boxes and Viewports First Steps
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
8. Loading PLplot
Introduction
To load PLplot, just use the bindings module:
First Steps
Loading PLplot
1 use strict;
Hello PLplot 2 use warnings;
Labels and Title 3 use PDL;
Setting the Device 4 use PDL::Graphics::PLplot;
Plotting Points 5
Multiple Curves 6 # ...
Boxes and Viewports
Other Methods To save myself keystrokes, I will make use of the aliased
Text module, available from CPAN, making these two pairs of
Using the mem
Device statements equivalent:
Miscellaneous 1 use aliased ’PDL::Graphics::PLplot’;
Conclusions
2 my $pl = PLplot->new( ’args...’ );
3
4 # works the same as:
5 use PDL::Graphics::PLplot;
6 my $pl = PDL::Graphics::PLplot->new( ’args...’ );
9. Hello PLplot
new([OPTIONS]) creates a new PLplot object
xyplot($x, $y, [OPTIONS]) plots x vs y data
close() closes the PLplot object and finalizes the plot
1 use strict; use warnings; use PDL;
2 use PDL::Graphics::PLplot;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7
8 # Prompts the user for the device
9 # and file name:
10 my $pl = PDL::Graphics::PLplot->new;
11
12 # Plot the time series
13 $pl->xyplot($time, $sinewave);
14
15 # Close the PLplot object to finalize
16 $pl->close;
10. Labels and Title
How do we add axis labels and a title? Options XLAB, YLAB specify the axis
labels and TITLE specifies the plot title
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7
8 # Create the PLplot object:
9 my $pl = PLplot->new;
10
11 # Plot the time series
12 $pl->xyplot($time, $sinewave
13 , XLAB => ’time [s]’
14 , YLAB => ’position [cm]’
15 , TITLE => ’Mass on Spring’
16 );
17
18 # Close the PLplot object to finalize
19 $pl->close;
11. Setting the Device
Introduction
PLplot supports multiple devices. Specify them in your call to
First Steps
Loading PLplot
new. For output to a window:
Hello PLplot
Labels and Title s option DEV must be set to xwin, wxwidgets, or similar
Setting the Device
Plotting Points
Multiple Curves
For output to a file:
Boxes and Viewports
s option DEV must be set to xfig, svg, pscairo, or similar
Other Methods
Text s option FILE must give the output file’s name
Using the mem
Device
Miscellaneous
For output to a memory buffer:
Conclusions
s option DEV must be set to mem or memcairo
s option MEM must be passed a piddle where the results will
be plot
12. Setting the Device
Introduction 1 use strict; use warnings; use PDL;
First Steps 2 use PDL::Graphics::PLplot;
Loading PLplot 3
Hello PLplot 4 # Generate a time series
Labels and Title 5 my $time = sequence(100)/10;
Setting the Device 6 my $sinewave = 5 * sin($time);
Plotting Points 7
Multiple Curves 8 # Create a PLplot wxwidgets object:
Boxes and Viewports
9 my $pl = PDL::Graphics::PLplot->new(
10 DEV => ’wxwidgets’
Other Methods
11 );
Text 12
Using the mem 13 # Plot the time series
Device
14 $pl->xyplot($time, $sinewave
Miscellaneous 15 , XLAB => ’time [s]’, YLAB => ’position [cm]’
Conclusions 16 , TITLE => ’Mass on Spring’
17 );
18
19 # Close the PLplot object to finalize
20 $pl->close;
13. Setting the Device
Introduction 1 use strict; use warnings; use PDL;
First Steps 2 use PDL::Graphics::PLplot;
Loading PLplot 3
Hello PLplot 4 # Generate a time series
Labels and Title 5 my $time = sequence(100)/10;
Setting the Device 6 my $sinewave = 5 * sin($time);
Plotting Points 7
Multiple Curves 8 # Save the image to a postscript file
Boxes and Viewports
9 my $pl = PDL::Graphics::PLplot->new(
10 DEV => ’ps’
Other Methods 11 , FILE => ’myfile.eps’
Text 12 );
Using the mem 13
Device
14 # Plot the time series
Miscellaneous 15 $pl->xyplot($time, $sinewave
Conclusions 16 , XLAB => ’time [s]’, YLAB => ’position [cm]’
17 , TITLE => ’Mass on Spring’
18 );
19
20 # Close the PLplot object to finalize
21 $pl->close;
14. Plotting Points
Introduction
You can plot lines, symbols, or both by using the PLOTTYPE
First Steps
Loading PLplot
option. You specify error bars in x and y by passing a scalar or a
Hello PLplot piddle with those errors to XERRORBAR and YERRORBAR.
Labels and Title
Setting the Device
Plotting Points
s PLOTTYPE => LINE plots data as lines (default)
Multiple Curves
Boxes and Viewports
s PLOTTYPE => POINTS plots data as points
Other Methods
Text s PLOTTYPE => LINEPOINTS plots data as lines and points
Using the mem
Device
s PLplot’s built in error-bars can plot asymmetric error bars,
Miscellaneous
Conclusions
but the high-level PDL bindings do not support this.
15. Plotting Points
Introduction
To set the symbol type and size, use the SYMBOL and
First Steps
Loading PLplot
SYMBOLSIZE options.
Hello PLplot
Labels and Title
Setting the Device s Symbol sizes are measured as multiples of the default size
Plotting Points
Multiple Curves s Symbol sizes can be fractional, such as 0.7 or 4.5
Boxes and Viewports
Other Methods s Symbols are identified by their number
Text
Using the mem s Symbol numbers are shown on the PLplot demo page 7 at
Device
http://plplot.sourceforge.net/examples.php?demo=07
Miscellaneous
1
Conclusions
1
Warning: I had to choose a symbol numbered 200 or higher. YMMV.
16. Symbols Example
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7
8 # Save the image to a postscript file
9 my $pl = PLplot->new(
10 DEV => ’pscairo’
11 , FILE => ’Symbols.eps’
12 );
13
14 # Plot the time series as points
15 $pl->xyplot($time, $sinewave
16 , PLOTTYPE => ’POINTS’
17 , SYMBOL => 843
18 , YERRORBAR => grandom($time)/2
19 );
20
21 $pl->close;
17. Introduction
First Steps
Multiple Curves
TIMTOWTDI
Multidim Piddles
Multiple xyplots
Problems
Solutions
stripplots
stripplots and Multiple Curves
rcols
SUBPAGES
Insets
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
18. TIMTOWTDI
Introduction
Depending on what you want, there are at least five ways to plot
First Steps
multiple curves on a plot.
Multiple Curves
TIMTOWTDI
Multidim Piddles s plot a multidimensional piddle
Multiple xyplots
Problems
Solutions s call xyplot multiple times
stripplots
stripplots and
rcols
s use stripplots
SUBPAGES
Insets s specify SUBPAGES in the constructor
Boxes and Viewports
Other Methods s create insets using the VIEWPORT option
Text
Using the mem
Device
Miscellaneous
Conclusions
19. Multidimensional Piddles
The easiest way to plot multiple curves is to create a multi-dimensional piddle
that you plot with xyplot:
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 4 * cos($time);
8 my $toplot = cat($sinewave, $cosinewave);
9
10 # Save the image to a postscript file
11 my $pl = PLplot->new(
12 DEV => ’pscairo’
13 , FILE => ’Multidimensional.eps’
14 );
15
16 # Plot the time series
17 $pl->xyplot($time, $toplot);
18
19 $pl->close;
20. Multidimensional Piddles
Introduction
Use color to differentiate different data sets:
First Steps
Multiple Curves
TIMTOWTDI
s For multidimensional piddles, plot as POINTS and use the
Multidim Piddles COLORMAP and PALETTE options.
Multiple xyplots
Problems
Solutions s For multiple calls to xyplot, use POINTS, COLORMAP, and
stripplots PALETTE, or use COLOR option.
stripplots and
rcols
SUBPAGES
Insets
The COLORMAP option lets you specify a third value for each
Boxes and Viewports (x, y) pair, making it (x, y, colorval).
Other Methods Which color is associated with the minimum colorval? Which
Text color is associated with the maximum value? All of these are set
Using the mem
Device
with the PALETTE.
Miscellaneous
Conclusions
21. Multidimensional Piddles
Introduction
Valid PALETTEs include:
First Steps
RAINBOW - from red to violet through the spectrum
Multiple Curves
TIMTOWTDI REVERSERAINBOW - violet through red
Multidim Piddles
Multiple xyplots
GREYSCALE - from black to white via grey
Problems REVERSEGREYSCALE - from white to black via grey
Solutions
stripplots
GREENRED - from green to red
stripplots and
rcols
REDGREEN - from red to green
SUBPAGES
Insets
Note:
Boxes and Viewports
s the default palette is not named
Other Methods
Text
s this only works when plotting points, not lines or error bars
Using the mem
Device
Miscellaneous
Conclusions
22. Multidimensional Piddles
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3 my $pl = PLplot->new(
4 DEV => ’pscairo’
5 ,FILE => ’Multidimensional2.eps’);
6
7 # Generate a time series and phase offset
8 my $time = sequence(100)/10;
9 my $phi = zeroes(4)->xlinvals(0, 3)
10 ->transpose;
11 my $sinewaves = 5*sin($time + $phi);
12 # Plot the time series and phi color key
13 $pl->xyplot($time, $sinewaves
14 , PLOTTYPE => ’POINTS’
15 , COLORMAP => $phi
16 , TITLE => ’sin(x + #gf)’);
17 $pl->colorkey($phi, ’v’
18 , TITLE => ’#gf’
19 , VIEWPORT
20 => [0.93, 0.96, 0.15, 0.85]);
21 $pl->close;
23. Call xyplot multiple times
Introduction
Another way to plot multiple curves on the same plot is to call
First Steps
xyplot multiple times, specifying the COLOR option.
Multiple Curves
TIMTOWTDI BLACK GREEN WHEAT
Multidim Piddles
Multiple xyplots BLUE RED AQUAMARINE
Problems
GREY BLUEVIOLET YELLOW
Solutions
stripplots PINK BROWN CYAN
stripplots and
rcols TURQUOISE MAGENTA SALMON
SUBPAGES WHITE ROYALBLUE DEEPSKYBLUE
Insets
Boxes and Viewports
VIOLET STEELBLUE1 DEEPPINK
Other Methods
MAGENTA DARKORCHID1 PALEVIOLETRED2
Text TURQUOISE1 LIGHTSEAGREEN SKYBLUE
Using the mem FORESTGREEN CHARTREUSE3 GOLD2
Device
Miscellaneous
SIENNA1 CORAL HOTPINK
Conclusions
LIGHTCORAL LIGHTPINK1 LIGHTGOLDENROD
24. Call xyplot multiple times
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 4 * cos($time);
8
9 # Save the image to a postscript file
10 my $pl = PLplot->new(
11 DEV => ’pscairo’
12 , FILE => ’Multiple curves.eps’
13 );
14
15 # Plot the sine in black, cosine in red
16 $pl->xyplot($time, $sinewave);
17 $pl->xyplot($time, $cosinewave
18 , COLOR => ’RED’);
19
20 $pl->close;
25. Problems with multiple xyplot calls
Introduction
Things can easily go awry and not Do What You Mean:
First Steps
Multiple Curves
TIMTOWTDI
s Curve clipping - the first plot sets the plotting boundaries
Multidim Piddles and later plots fall outside of those boundaries
Multiple xyplots
Problems
Solutions s Changing ‘current’ color - the first plot sets the ‘current’
stripplots color and the second does not specify a color
stripplots and
rcols
SUBPAGES
Insets
Also, PLplots has a discrete color limit of 16, including
Boxes and Viewports foreground and background color.
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
26. Curve Clipping
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 6 * cos($time);
8
9 # Save the image to a postscript file
10 my $pl = PLplot->new(
11 DEV => ’pscairo’
12 , FILE => ’Multiple curves2.eps’
13 );
14
15 # Plot the sine in black, cosine in red
16 $pl->xyplot($time, $sinewave);
17 $pl->xyplot($time, $cosinewave
18 , COLOR => ’RED’);
19
20 $pl->close;
27. Changing Current Colors
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 6 * cos($time);
8
9 # Save the image to a postscript file
10 my $pl = PLplot->new(
11 DEV => ’pscairo’
12 , FILE => ’Color wart.eps’
13 );
14
15 # Plot the cosine in red
16 $pl->xyplot($time, $cosinewave
17 , COLOR => ’RED’);
18 # Plot the sine in black
19 # ERROR: current color is red!
20 $pl->xyplot($time, $sinewave);
21
22 $pl->close;
28. Solution to Changing Current Color
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 6 * cos($time);
8
9 # Save the image to a postscript file
10 my $pl = PLplot->new(
11 DEV => ’pscairo’
12 , FILE => ’Color solution.eps’
13 );
14
15 # Plot the cosine in red
16 $pl->xyplot($time, $cosinewave
17 , COLOR => ’RED’);
18 # Plot the sine in black
19 $pl->xyplot($time, $sinewave
20 , COLOR => ’BLACK’);
21
22 $pl->close;
29. Solution to Curve Clipping
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7 my $cosinewave = 6 * cos($time);
8
9 # Save the image to a postscript file
10 my $pl = PLplot->new(
11 DEV => ’pscairo’
12 , FILE => ’Multiple curves3.eps’
13 );
14
15 # Plot the sine with full bounds
16 $pl->xyplot($time, $sinewave
17 , BOX => [$time->minmax
18 , $cosinewave->minmax]);
19 # Plot the cosine in red
20 $pl->xyplot($time, $cosinewave
21 , COLOR => ’RED’);
22
23 $pl->close;
30. stripplots
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Save the image to a postscript file
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’stripplots.eps’
8 );
9
10 # Generate a time series
11 my $time = sequence(100)/10;
12
13 # Make stripplots with the
14 # different time series
15 $pl->stripplots($time
16 , [sin($time), cos($time)]
17 , XLAB => ’x’
18 , YLAB => [’sine’, ’cosine’]
19 , COLOR => [’BLUE’, ’RED’]
20 , TITLE => ’Sine and Cosine’
21 );
22
23 $pl->close;
31. stripplots
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Save the image to a postscript file
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’stripplots.eps’
8 );
9
10 # Generate a time series
11 my $time = sequence(100)/10;
12 my $data
13 = cat(sin($time), cos($time));
14 # Make stripplots with the
15 # different time series
16 $pl->stripplots($time, $data
17 , XLAB => ’x’
18 , YLAB => [’sine’, ’cosine’]
19 , COLOR => [’BLUE’, ’RED’]
20 , TITLE => ’Sine and Cosine’
21 );
22
23 $pl->close;
32. stripplots and rcols
Introduction 1 use strict; use warnings; use PDL;
First Steps 2 use PDL::Graphics::PLplot;
3
Multiple Curves
4 my ($t, $data) = rcols(*DATA, 0, []);
TIMTOWTDI
Multidim Piddles
5
Multiple xyplots 6 my $pl = PDL::Graphics::PLplot->new;
Problems 7
Solutions 8 # Make stripplots with the different time series
stripplots 9 $pl->stripplots($t, $data->transpose);
stripplots and 10
rcols
11 $pl->close;
SUBPAGES
Insets
12
13 DATA
Boxes and Viewports
14 # t x1 x2 x3
Other Methods 15 1 4 6 -1
Text 16 2 3 9 3
Using the mem
17 3 2 8 7
Device 18 3 -1 4 10
Miscellaneous
19 5 1 2 6
20 6 5 -1 5
Conclusions
33. SUBPAGES
Introduction
When you create your PLplot object, you can carve the canvas
First Steps
into immutable subpages.
Multiple Curves
TIMTOWTDI 1 my $pl = PDL::Graphics::PLplot->new(
Multidim Piddles 2 # ...
Multiple xyplots 3 , SUBPAGES => [$nx, $ny]
Problems 4 );
Solutions
stripplots To advance to a new subpage, specify the SUBPAGE option.
stripplots and
rcols
1 # Advance to next subpage
SUBPAGES 2 $pl->xyplot($x, $y
Insets 3 # other options...
4 , SUBPAGE => 0
Boxes and Viewports
5 # other options...
Other Methods 6 );
Text 7
Using the mem 8 # Advance to fourth subpage
Device 9 $pl->xyplot($x, $y
Miscellaneous 10 # other options...
11 , SUBPAGE => 4
Conclusions
12 # other options...
13 );
34. SUBPAGES
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6
7 # Save the image to a postscript file
8 my $pl = PLplot->new(
9 DEV => ’pscairo’
10 , FILE => ’subpages.eps’
11 , SUBPAGES => [2,2]);
12
13 # Plot the time series
14 $pl->xyplot($time, sin($time)
15 , TITLE => ’Sine’);
16 $pl->xyplot($time, cos($time)
17 , TITLE => ’Cosine’, SUBPAGE => 0);
18 $pl->xyplot($time, tan($time)
19 , TITLE => ’Tangent’, SUBPAGE => 4);
20 $pl->xyplot($time, $time**2
21 , TITLE => ’Squared’, SUBPAGE => 3);
22
23 $pl->close;
35. Insets
Sometimes you want a small inset in one of the corners of your plot. If you
want to do this you should:
s Specify the VIEWPORT
s Specify the BOX
s Use a smaller CHARSIZE
s If the underlying plot has a title, you should probably undefine it
s undefine or change the XLAB and YLAB unless you want to use the
values from the underlying plot
36. Insets
1 use strict; use warnings;
2 use PDL::Graphics::PLplot;
3 use PDL; use PDL::NiceSlice;
4
5 # Generate a noisy time series
6 my $time = sequence(1000) /10;
7 my $sinewave = 1 * sin($time) + grandom($time) / 3;
8
9 # Save the image to a postscript file
10 my $pl = PDL::Graphics::PLplot->new(DEV => ’pscairo’, FILE => ’inset.eps’);
11
12 # Plot subset as the main plot
13 $pl->xyplot($time(0:65), $sinewave(0:65), TITLE => ’Noisy Pendulum’
14 , YLAB => ’Displacement d [m]’, XLAB => ’Time t [s]’);
15
16 # Plot full data set as inset
17 $pl->xyplot($time, $sinewave
18 , TITLE => undef
19 , VIEWPORT => [0.525, 0.825, 0.525, 0.775]
20 , BOX => [$time->minmax, $sinewave->minmax]
21 , CHARSIZE => 0.6
22 );
23 $pl->close;
38. Introduction
First Steps
Multiple Curves
Boxes and Viewports
Three Layers
Surface Dimensions
Viewport Positioning
Clipping Box
Examples
Summary
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
39. Three Layers of Coordinates
Introduction
PLplot has three distinct measurements for your plot at any
First Steps
point:
Multiple Curves
Boxes and Viewports
Three Layers s the plotting surface’s dimensions
Surface Dimensions
Viewport Positioning s the viewport’s relative extent
Clipping Box
Examples
Summary s the ‘natural’ coordinates within the viewport
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
40. Surface Dimensions
Introduction
The dimensions of the canvas or surface that you are using can
First Steps
be specified in the constructor (and cannot be changed later):
Multiple Curves
1 my $pl = PDL::Graphics::PLplot->new(
Boxes and Viewports
2 # other options...
Three Layers
Surface Dimensions
3 PAGESIZE => [$width, $height]
Viewport Positioning 4 # other options...
Clipping Box 5 );
Examples
Summary
Other Methods
These are measured either in pixels or milimeters depending on
Text
whether the underlying format is a raster or vector format.
Using the mem
Device
Miscellaneous
Conclusions
41. Viewport Positioning
Introduction
The viewport carves out a chunk of space on the canvas for
First Steps
plotting and can be changed with each plotting function.
Multiple Curves
1 $pl->xyplot($x, $y
Boxes and Viewports
2 # other options
Three Layers
Surface Dimensions
3 , VIEWPORT => [$xmin, $xmax, $ymin, $ymax]
Viewport Positioning 4 # other options
Clipping Box 5 );
Examples 6
Summary 7 # Plot on right half of the page
Other Methods
8 VIEWPORT => [0.5, 1, 0, 1]
9 # Plot in upper half of the page
Text
10 VIEWPORT => [0, 1, 0, 0.5]
Using the mem 11 # Vertically centered, horizontally offset
Device
12 VIEWPORT => [0.5, 0.7, 0.4, 0.6]
Miscellaneous
Conclusions
Viewport values are fractions of the full page (or sub-page) width
– all four values should be a number between 0 and 1.
42. Clipping Box
Introduction
If the viewport indicates the chunk of space you will be graphing
First Steps
on, the clipping box indicates the coordinates within that chunk
Multiple Curves
of space.
Boxes and Viewports
1 $pl->xyplot($x, $y
Three Layers
2 # other options...
Surface Dimensions
Viewport Positioning
3 , BOX => [$xmin, $xmax, $ymin, $ymax]
Clipping Box 4 # other options...
Examples 5 );
Summary 6
Other Methods
7 # x runs from 0 to 10, y from -8 to 8:
8 BOX => [0, 10, -8, 8]
Text 9 # piddles have the minmax method:
Using the mem 10 BOX => [$x pdl->minmax, $y pdl->minmax]
Device
Miscellaneous
Conclusions When plotting using the specified box, a data point near (0, −8)
will be plotted near the lower left corner and a data point near
(5, 0) will be plotted at the center.
Viewports define where plots are drawn. Tick labels, axis labels,
and plot titles are drawn outside the viewport.
43. Examples
Introduction
Here are some examples to show how each of these work.
First Steps
Multiple Curves
Boxes and Viewports
Three Layers
Surface Dimensions
Viewport Positioning
Clipping Box
Examples
Summary
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
44. Starting Example
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6
7 # Set the backgound to blue:
8 my $pl = PLplot->new(
9 DEV => ’pscairo’
10 , FILE => ’box example 1.eps’
11 , BACKGROUND => ’SKYBLUE’
12 );
13
14 # Plot a quadratic function:
15 $pl->xyplot($x, $y
16 , YLAB => ’y’, XLAB => ’x’);
17
18 $pl->close;
I set the background to blue so you can see the extent of the canvas.
45. Page Size Example
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6
7 # Set a custom page size
8 my $pl = PLplot->new(
9 DEV => ’pscairo’
10 , FILE => ’box example 2.eps’
11 , BACKGROUND => ’SKYBLUE’
12 , PAGESIZE => [360, 240]
13 );
14
15 # Plot a quadratic function:
16 $pl->xyplot($x, $y
17 , YLAB => ’y’, XLAB => ’x’);
18
19 $pl->close;
46. Viewport Example - Upper Right
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6 my $pl = PLplot->new(
7 DEV => ’pscairo’
8 , FILE => ’box example 3.eps’
9 , BACKGROUND => ’SKYBLUE’
10 );
11
12 # Put the plot in the upper right:
13 $pl->xyplot($x, $y
14 , YLAB => ’y’, XLAB => ’x’
15 , VIEWPORT
16 => [0.5, 0.9, 0.6, 0.8]);
17
18 $pl->close;
47. Viewport Example - Centered
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6 my $pl = PLplot->new(
7 DEV => ’pscairo’
8 , FILE => ’box example 4.eps’
9 , BACKGROUND => ’SKYBLUE’
10 );
11
12 # Center the plot
13 $pl->xyplot($x, $y
14 , YLAB => ’y’, XLAB => ’x’
15 , VIEWPORT
16 => [0.3, 0.7, 0.3, 0.7]);
17
18 $pl->close;
48. Viewport Example - Extreme Bounds
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6 my $pl = PLplot->new(
7 DEV => ’pscairo’
8 , FILE => ’box example 5.eps’
9 , BACKGROUND => ’SKYBLUE’
10 );
11
12 # Try extreme bounds for the viewport
13 $pl->xyplot($x, $y
14 , YLAB => ’y’, XLAB => ’x’
15 , VIEWPORT
16 => [0, 1, 0.3, 1]);
17
18 $pl->close;
49. Viewport Example - Multiple Plots
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $y = $x**2;
6 my $pl = PLplot->new(
7 DEV => ’pscairo’
8 , FILE => ’box example 6.eps’
9 , BACKGROUND => ’SKYBLUE’);
10
11 # Big plot on left
12 $pl->xyplot($x, $y, VIEWPORT
13 => [0.1, 0.6, 0.1, 0.8]);
14 # Medium plot on upper right
15 $pl->xyplot($x, $y, VIEWPORT
16 => [0.5, 0.9, 0.6, 0.9]);
17 # Small plot on lower right
18 $pl->xyplot($x, $y, VIEWPORT
19 => [0.7, 0.9, 0.1, 0.4]);
20
21 $pl->close;
50. Box Example - Default Box
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’box example 7.eps’
8 , BACKGROUND => ’SKYBLUE’);
9
10 # Sine wave on top
11 $pl->xyplot($x, sin($x), VIEWPORT
12 => [0.1, 0.9, 0.55, 0.9]);
13 # Quadratic on bottom
14 # BOX is inherited from first plot
15 $pl->xyplot($x, $x**2, VIEWPORT
16 => [0.1, 0.9, 0.1, 0.45]);
17
18
19 $pl->close;
51. Box Example - Tweaked Box
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’box example 8.eps’
8 , BACKGROUND => ’SKYBLUE’);
9
10 # Sine wave on top
11 $pl->xyplot($x, sin($x), VIEWPORT
12 => [0.1, 0.9, 0.55, 0.9]);
13 # Quadratic on bottom
14 $pl->xyplot($x, $x**2, VIEWPORT
15 => [0.1, 0.9, 0.1, 0.45]
16 , BOX => [-3, 3, 0, 9]);
17
18
19 $pl->close;
52. Box Example - Two Plots
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’box example 9.eps’
8 , BACKGROUND => ’SKYBLUE’);
9
10 # Sine wave
11 $pl->xyplot($x, sin($x));
12
13 # Plotting a quadratic on top works
14 # but the bounds are not good
15 $pl->xyplot($x, $x**2);
16
17 $pl->close;
53. Box Example - Changing Box but not Viewport
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $x = zeroes(20)->xlinvals(-3, 3);
5 my $pl = PLplot->new(
6 DEV => ’pscairo’
7 , FILE => ’box example 10.eps’
8 , BACKGROUND => ’SKYBLUE’);
9
10 # Sine wave
11 $pl->xyplot($x, sin($x));
12
13 # Changing the box for the quadratic
14 # does not work - bad y ticks
15 $pl->xyplot($x, $x**2
16 , BOX => [-3, 3, 0, 9]);
17
18 $pl->close;
54. Summary
Introduction
First Steps
s For multiple plots on the same viewport, set the box with
Multiple Curves
the first call to xyplot
Boxes and Viewports
Three Layers s For non-overlapping plots (on different viewports), specify
Surface Dimensions
Viewport Positioning
the box as necessary
Clipping Box
Examples s The viewport specifies the extent of the plotting region; tick
Summary
labels, axis labels, and titles are drawn outside the viewport
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
55. Introduction
First Steps
Multiple Curves
Boxes and Viewports
Other Methods
Sticky Options
Overview
shadeplot
histogram Other Methods
bargraph
setparm
Text
Using the mem
Device
Miscellaneous
Conclusions
56. Sticky Options
Introduction
Once you specify a plotting option, the option will carry over to
First Steps
future calls on the same PLplot object.
Multiple Curves
Boxes and Viewports
Other Methods
Sticky Options
Overview
shadeplot
histogram
bargraph
setparm
Text
Using the mem
Device
Miscellaneous
Conclusions
57. Overview
Introduction
The high-level object-oriented interface in PDL::Graphics::PLplot
First Steps
has a handful of methods:
Multiple Curves
Boxes and Viewports
new, close create and finalize plot objects
Other Methods
Sticky Options
Overview xyplot, stripplots 2D plotting
shadeplot
histogram
bargraph
shadeplot ‘topographical’ 3D data representation
setparm
Text histogram plot distribution of 1D data
Using the mem
Device bargraph plot distribution of categorical data
Miscellaneous
Conclusions text annotate plots
setparm set various plotting parameters
58. shadeplot
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’shadeplot2.eps’);
7
8 # Have x run from -10 to 10
9 # and y run from 1 to 7:
10 my $x = zeroes(51)
11 ->xlinvals(-10, 10);
12 my $y = zeroes(51)->xlinvals(1, 7);
13 # Define z = sin(x) + cos(y), a 2D piddle:
14 my $z = sin($x)
15 + cos($y->transpose);
16
17 # Make a shade plot with 15 color steps:
18 $pl->shadeplot($z, 15, BOX => [$x->minmax, $y->minmax]);
19
20 # Indicate the color scaling:
21 $pl->colorkey($z, ’v’, VIEWPORT => [0.93, 0.96, 0.15, 0.85]);
22
23 $pl->close;
59. shadeplot
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’shadeplot3.eps’);
7
8 # Define z = sin(x) + cos(y), a 2D piddle:
9 my $x=zeroes(51)->xlinvals(-10, 10);
10 my $y=zeroes(51)->xlinvals(1, 7);
11 my $z=sin($x) + cos($y->transpose);
12
13 # Make a shade plot with 15 color steps:
14 $pl->shadeplot($z, 15
15 , BOX => [$x->minmax, $y->minmax]
16 , XLAB => ’x’, YLAB => ’y’
17 , TITLE => ’Egg Carton’);
18 # Add a ’vertical’ color key:
19 $pl->colorkey($z, ’v’, VIEWPORT
20 => [0.93, 0.96, 0.15, 0.85]
21 , XLAB => ’’, YLAB => ’’, TITLE => ’depth’);
22
23 $pl->close;
60. histogram
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’histogram.eps’);
7
8 # Generate some data:
9 my $data = grandom(1000);
10
11 # Make a histogram of that data in 20 bins:
12 $pl->histogram($data, 20);
13
14 $pl->close;
61. histogram
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’histogram2.eps’);
7
8 # Generate some data:
9 my $data = grandom(1000);
10
11 # Get approximate binning:
12 my $nbins = 20;
13 my $binwidth =
14 ($data->max-$data->min) / $nbins;
15 my ($x, $y) = hist($data
16 , $data->minmax, $binwidth);
17
18 # Make a histogram of that data in 20 bins:
19 my $fudgefactor = 1.1;
20 $pl->histogram($data, $nbins
21 , BOX => [$x->minmax, 0, $y->max * $fudgefactor]);
22
23 $pl->close;
62. bargraph
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’bargraph.eps’);
7
8 # Generate some data:
9 my @colors = qw(red orange yellow
10 green blue purple);
11 my $votes = random(scalar(@colors));
12
13 # Normalize the votes
14 $votes /= $votes->sum;
15
16 # Make a barchart of the votes.
17 $pl->bargraph(@colors, $votes);
18
19 $pl->close;
63. bargraph
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’bargraph2.eps’);
7
8 # Generate some data:
9 my @colors = qw(red orange yellow
10 green blue purple);
11 my $votes = random(scalar(@colors));
12
13 # Normalize the votes
14 $votes /= $votes->sum;
15
16 # Make a barchart of the votes.
17 $pl->bargraph(@colors, $votes
18 , COLOR => ’BLUE’
19 , BOX => [0, scalar(@colors), 0, 1.1 * $votes->max]
20 );
21
22 $pl->close;
64. bargraph
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’bargraph3.eps’);
7
8 # voting on letters:
9 my @letters = (’a’ .. ’z’);
10 my $votes = random(0 + @letters);
11
12 # Normalize the votes
13 $votes /= $votes->sum;
14
15 # Make a barchart of the votes.
16 $pl->bargraph(@letters, $votes
17 , COLOR => ’LIGHTGOLDENROD’
18 , BOX => [0, scalar(@letters)
19 , 0, 1.1 * $votes->max]
20 , MAXBARLABELS => 10
21 );
22
23 $pl->close;
66. Introduction
First Steps
Multiple Curves
Boxes and Viewports
Other Methods
Text
Typesetting
Greek Letters
psfrag
Text
Annotations
Legends
Using the mem
Device
Miscellaneous
Conclusions
67. Typesetting
Introduction
Use escape sequences to insert superscripts, subscripts, Greek
First Steps
letters, etc.
Multiple Curves
#u - superscript until the next #d
Boxes and Viewports
#d - subscript until the next #u
Other Methods
#- - toggle underline mode
Text
Typesetting #+ - toggle overline mode
Greek Letters
psfrag
#fn - switch to normal (sans-serif) font
Annotations #fr - switch to Roman (serif) font
Legends
#fi - switch to italic font
Using the mem
Device #fs - switch to script font
Miscellaneous
Unicode is supported though I won’t get into it here.
Conclusions
68. Typesetting
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 # Generate a time series
5 my $time = sequence(100)/10;
6 my $sinewave = 5 * sin($time);
7
8 # Create the PLplot object:
9 my $pl = PLplot->new(
10 DEV => ’pscairo’
11 , FILE => ’Typesetting.eps’);
12
13 # Plot the time series
14 $pl->xyplot($time, $sinewave
15 , XLAB => ’#fi time #fn [Hz#u-1#d]’
16 , YLAB => ’#fiposition#fn [cm]’
17 , TITLE => ’#frMass on Spring’
18 );
19
20 # Close the PLplot object to finalize
21 $pl->close;
69. Greek Letters
Introduction
Use the string #gx to print the Greek letter equivalent of x:
First Steps
Multiple Curves
A B G D E Z Y H I K L M
Boxes and Viewports A B Γ ∆ E Z H Θ I K Λ M
Other Methods N C O P R S T U F X Q W
Text N Ξ O Π P Σ T Y Φ X Ψ Ω
Typesetting
Greek Letters a b g d e z y h i k l m
psfrag α β γ δ ζ η θ ι κ λ µ
Annotations
Legends n c o p r s t u f x q w
Using the mem ν ξ o π ρ σ τ υ φ χ ψ ω
Device
Miscellaneous 1 # Use greek symbol rho for density:
2 $pl->xyplot($radius, $density
Conclusions
3 , YLAB => ’density #gr’
4 , # ...
5 );
70. psfrag
Introduction
For LTEX typsetting, post-process eps images with psfrag.
A
First Steps
Multiple Curves
s replaces simple strings with any valid LTEX text.
A
Boxes and Viewports
Other Methods s ensures consistent fonts for both images and documents
Text
Typesetting
Greek Letters Do not use the pscairo device. Use ps or psc.
psfrag
Annotations
Legends
Using the mem
Device
Miscellaneous
Conclusions
71. Annotations
Introduction
To add text to a plot, use the text method, specifying the
First Steps
TEXTPOSITION option. The TEXTPOSITION takes either four or
Multiple Curves
five arguments. The four-argument form places text outside the
Boxes and Viewports
Other Methods
viewport along one of its edges:
Text
1 $pl->text($string, TEXTPOSITION => [$side, $disp, $pos, $just]);
Typesetting
Greek Letters
psfrag $side is one of ’t’, ’b’, ’l’, or ’r’ indicating the top, bottom, left,
Annotations
Legends
or right edge
Using the mem $disp is the number of character heights out from the edge
Device
Miscellaneous $pos is the position of the string’s reference point along the
Conclusions edge of the viewport, from 0 to 1
$just indicates the location of the reference point of the string.
0 means the reference point is the string’s left edge; 1 indicates
the right edge
72. Annotations
Introduction
The five-argument form places the text within the viewport at an
First Steps
arbitrary position and slope:
Multiple Curves
1 $pl->text($string, TEXTPOSITION => [$x, $y, $dx, $dy, $just]);
Boxes and Viewports
Other Methods
Text
$x, $y are the location of the string’s reference point within the
Typesetting clipping box
Greek Letters
psfrag
Annotations
$dx, $dy together indicate the slope along which the text is
Legends drawn
Using the mem
Device $just indicates the location of the reference point of the string.
Miscellaneous 0 means the reference point is the string’s left edge; 1 indicates
Conclusions the right edge
73. Annotations
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’text1.eps’);
7
8 my $x = zeroes(100)->xlinvals(-3,3);
9 my $y = $x**2;
10 $pl->xyplot($x, $y);
11
12 $pl->setparm(CHARSIZE => 1.2);
13 # x label on the lower right
14 $pl->text(’Position x [m]’,
15 , TEXTPOSITION => [’b’, 3, 1, 1]);
16 # y label on the upper left
17 $pl->text(’Potential Energy V [J]’
18 , TEXTPOSITION => [’l’, 3.5, 1, 1]);
19 # title at the center top
20 $pl->text(’Harmonic Oscillator’
21 , CHARSIZE => 2.5, TEXTPOSITION => [’t’, 1.5, 0.5, 0.5]);
22
23 $pl->close;
74. Annotations
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3
4 my $pl = PLplot->new(
5 DEV => ’pscairo’
6 , FILE => ’text2.eps’);
7
8 # Plot a quadratic
9 my $x = zeroes(100)->xlinvals(-3,3);
10 my $y = $x**2;
11
12 $pl->xyplot($x, $y, TITLE => ’SHO’
13 , XLAB => ’Position x [m]’
14 , YLAB => ’Potential V [J]’);
15
16 # annotate negative slope at (-2, 4)
17 $pl->text(’Slope is negative’
18 , TEXTPOSITION => [-1.8, 4.1, 1, -4, 0.5]);
19 # annotate positive slope at (2, 4)
20 $pl->text(’Slope is positive’
21 , TEXTPOSITION => [1.9, 3.9, 10, 40, 1]);
22
23 $pl->close;
75. Legends
Introduction
PLplot does not have a command to create legends. We must
First Steps
make them ourselves.
Multiple Curves
Boxes and Viewports
Legends are only necessary when plotting discrete data sets.
Other Methods
Text
Typesetting
If possible, use color keys instead of constructing legends by
Greek Letters hand.
psfrag
Annotations
Legends
Using the mem
Device
Miscellaneous
Conclusions
76. Legends
Introduction 1 use strict; use warnings; use PDL;
First Steps 2 use PDL::Graphics::PLplot;
3 my $pl = PDL::Graphics::PLplot->new(DEV => ’pscairo’
Multiple Curves
4 , FILE => ’legend.eps’);
Boxes and Viewports 5
Other Methods 6 my $x = zeroes(100)->xlinvals(-1.2, 1.2);
Text
7 my @colors = qw(BLACK GREEN BLUE);
Typesetting
8 my @labels = qw(Linear Quadratic Cubic);
Greek Letters 9
psfrag 10 my $legend x = pdl(0.3, 0.5);
Annotations 11 my $legend y = -0.5;
Legends 12
Using the mem 13 # Plot linear, quadratic, and cubic curves with a legend
Device 14 for my $i (0..2) {
Miscellaneous 15 $pl->xyplot($x, $x**($i+1), COLOR => $colors[$i]);
16 $pl->xyplot($legend x, pdl($legend y, $legend y)
Conclusions
17 , COLOR => $colors[$i]);
18 $pl->text($labels[$i], COLOR => ’BLACK’
19 , TEXTPOSITION => [0.6, $legend y, 1, 0, 0]);
20 $legend y -= 0.2;
21 }
22
23 $pl->close;
80. Introduction
First Steps
Multiple Curves
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Uses for mem Device
Using the mem Device
Creating a Memory
Buffer
Plotting over an
image
Miscellaneous
Conclusions
81. Uses for mem Device
Introduction
First Steps
s load an image and plot over that image
Multiple Curves
s plot to a custom windowing device
Boxes and Viewports
Other Methods
s animated plots
Text
Using the mem
Device
Uses for mem Device
Creating a Memory
Buffer
Plotting over an
image
Miscellaneous
Conclusions
82. Creating a Memory Buffer
Introduction 1 ## For the mem device ##
First Steps 2
3 # Allocate the buffer
Multiple Curves
4 my $buffer = zeroes(byte, 3, $width, $height);
Boxes and Viewports 5
Other Methods 6 # Create the PLplot object
Text
7 my $pl = PDL::Graphics::PLplot->new(
8 DEV => ’mem’
Using the mem
Device 9 , MEM => $buffer
Uses for mem Device 10 );
Creating a Memory 11
Buffer
Plotting over an 12
image 13 ## For the memcairo device ##
Miscellaneous 14
15 # Allocate the buffer
Conclusions
16 my $buffer = zeroes(byte, 4, $width, $height);
17
18 # Create the PLplot object
19 my $pl = PDL::Graphics::PLplot->new(
20 DEV => ’memcairo’
21 , MEM => $buffer
22 );
83. Plotting over an image
1 use strict; use warnings; use PDL;
2 use aliased ’PDL::Graphics::PLplot’;
3 use PDL::IO::Pic;
4
5 # Load an image
6 # (has dims 3 x width x height)
7 my $pic = rpic(’starry night.jpg’);
8 # Flip the y axis
9 $pic = $pic->slice(’:,:,-1:0:-1’);
10 # Whiten the image a bit
11 $pic = 127 + $pic / 2;
12
13 my $pl = PLplot->new(DEV => ’mem’
14 , MEM => $pic);
15
16 # Plot a quadratic curve over the image
17 my $x=zeroes(51)->xlinvals(-10, 10);
18 $pl->xyplot($x, $x**2);
19 $pl->close;
20
21 # flip the y axis back and save the image
22 $pic = $pic->slice(’:,:,-1:0:-1’);
23 wpic($pic, ’starry plot.png’);
85. use aliased
Introduction
The aliased module, available on CPAN, makes dealing with
First Steps
length package names much simpler:
Multiple Curves
1 use strict;
Boxes and Viewports
2 use warnings;
Other Methods 3 use PDL;
Text
4 use aliased ’PDL::Graphics::PLplot’;
Using the mem 5
Device 6 my $pl = PLplot->new(DEV => ’pscairo’
Miscellaneous
7 , FILE => ’text.eps’);
use aliased 8
Log plots 9 # ...
Bad Values
Conclusions
86. Log plots
Introduction
If you need to have one (or both) axes to have a log scale, use
First Steps
the XBOX or YBOX option, these let you determine certain aspects
Multiple Curves
of the x and y ticks and tick labels.
Boxes and Viewports
Other Methods
1 $pl->xyplot(log($x), $y
2 # include ’l’ for a logarithmic axis
Text 3 , XBOX => ’bclnst’
Using the mem 4 );
Device
Miscellaneous
use aliased
Log plots
Bad Values
Conclusions
87. Bad Values
Introduction
The PDL wrapper to PLplot supports bad values.
First Steps
Multiple Curves
Bad values are not plotted, and a gap is inserted into the plot.
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Miscellaneous
use aliased
Log plots
Bad Values
Conclusions
88. Introduction
First Steps
Multiple Curves
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Conclusions
Miscellaneous
Conclusions
What I Skipped
Strengths and
Weaknesses
Improvements
Other
Documentation
89. What I Skipped
Introduction
First Steps
s the many low-level commands
Multiple Curves
s 3D plots (using low-level commands)
Boxes and Viewports
Other Methods
s options for creation: BACKGROUND, JUST, OPTS,
Text
Using the mem
ORIENTATION
Device
Miscellaneous s plotting options: LINEWIDTH, LINESTYLE,
Conclusions MAJTICKSIZE, MINTICKSIZE, NXSUB, NYSUB, XBOX,
What I Skipped
Strengths and
XTICK, YBOX, YTICK, ZRANGE
Weaknesses
Improvements
Other
Documentation
90. Strengths and Weaknesses
Introduction
The PDL PLplot bindings are excellent at plotting 2D data.
First Steps
Multiple Curves
The bindings are poor for 3D plotting and have many quirks.
Boxes and Viewports
Other Methods
Text
Using the mem
Device
Miscellaneous
Conclusions
What I Skipped
Strengths and
Weaknesses
Improvements
Other
Documentation
91. Improvements
Introduction
First Steps
s better overall documentation
Multiple Curves
s bring low-level functions up-to-date with current PLplot
Boxes and Viewports
Other Methods
library
Text
Using the mem
s create low-level wrappers for colored error bars and lines
Device
Miscellaneous s better handling of histograms and bargraphs with more
Conclusions options
What I Skipped
Strengths and
Weaknesses s high level 3D plotting
Improvements
Other
Documentation s Alien::PLplot
92. Other Documentation
Introduction
PLplot’s web site:
First Steps
http://plplot.sourceforge.net/documentation.php.
Multiple Curves
Boxes and Viewports
PDL::Graphics::PLplot:
Other Methods
http://pdl.perl.org/?docs=Graphics/PLplot&title=PDL::Gra
Text
Using the mem
Device
Miscellaneous
Conclusions
What I Skipped
Strengths and
Weaknesses
Improvements
Other
Documentation