[8a974e]: PDL / Book / PLplot.pod  Maximize  Restore  History

Download this file

1645 lines (1191 with data), 47.6 kB

=for comment
:!podchecker PLplot.pod && pod2html --infile=PLplot.pod --outfile=PLplot.html
open PLplot.html and click 'reload'
also
conversion for PDF reading is:
pod2pdf PLplot.pod --icon-scale 0.25 --title "PDL Book" --icon logo2.png --output-file PLplot.pdf

=head1 Graphics with PLplot

The B<PDL::Graphics::PLplot> perl module, is an interface to the 
L<http://plplot.sourceforge.net> PLplot C library. It is a
2d plotting library, but also does 1-D bargraphs and 3-D projection graphs.

Many of the examples, discussed below, are from the
PDL::Graphics-PLplot/t subdirectory, of the source module. These are
written in the functional style, and are direct translations of the
examples which come with the B<PLplot C library> 

The rest of the examples, are object-oreiented, derived from David
Merten's slideshow on B<PDL::Graphics::PLplot>.  His very informative
slideshow can be downloaded or viewed at
L<http://www.slideshare.net/dcmertens/p-lplot-talk>

=head2 Introducing C<PDL::Graphics::PLplot>

The basic methods available:

  new, close ->  create and finalize plot objects
  xyplot, stripplots ->   2D plotting
  shadeplot ->   `topographical' 3D data representation
  histogram ->   plot distribution of 1D data
  bargraph ->    plot distribution of categorical data
  text ->   annotate plots
  setparm ->  set various plotting parameters

Once you specify a plotting option, the option will carry over to
future calls on the same PLplot object.

The first thing you will notice about invoking PLplot, is that it will
prompt you for an output device, or maybe a file to save to, if you do
not specify one either in B<perldl> or a script

=for html
<p> <b><center>Figure 00</b>: using PDL::Graphics::PLplot, invoking the output device menu.</center><br>
<center><img WIDTH=400 src="PLplot/w00.pl.800.png"></center>


You can specify a device 

   To specify the output device:

      pdl> dev('/xwin')
   
   or in a script
      
      use PDL::Graphics::PLplot;
      # display the image in the xwindow
      my $pl = PDL::Graphics::PLplot->new(
                    DEV => 'xwin'
                    );
                  

=head2 Plotting a simple parabola

This code:

        #!/usr/bin/perl
	use warnings;
	use strict;
	use PDL;
	use PDL::Graphics::PLplot;
        my $pl = PDL::Graphics::PLplot->new( DEV => "png", FILE => "$0.png" );
	my $x  = sequence( 10 );
	my $y  = $x**2;
	$pl->xyplot( $x, $y );	
	$pl->close;

produces a nice parabola, in a PNG file. 

=for html
<b><center>A parabola</center></b>
<center><img WIDTH=400 src="PLplot/w01.pl.800.png"></center>
<p>

=head2 Object Oriented Examples

This section shows how to use the object oriented methods of the B<Perl> interface
to B<PDL::Graphics::PLplot> 


=head3 Axis labelling and titles

	use PDL;
	use PDL::Graphics::PLplot;

	# Generate a time series
	my $time = sequence(100)/10;
	my $sinewave = 5 * sin($time);
	# Create the PLplot object: use xwin for display
	my $pl = PDL::Graphics::PLplot->new( DEV => "xwin");

	# Plot the time series
	$pl->xyplot($time, $sinewave
	     , XLAB => 'time [s]'
	     , YLAB => 'position [cm]'
	     , TITLE => 'Mass on Spring'
	     );
	# Close the PLplot object to finalize
	$pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w02.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w02.pl.html>w02.pl highlighted  source code</a></center>
<center> <a href=PLplot/w02.pl> w02.pl text source code</a></center><hr><p>   



=head2 Interactive crosshairs with the C<wxwidgets> output device

	# Create the PLplot object: use wxwidgets for display
	# wxwidgets allows saving to many file types, and
	# has a Locate function under the Plot menu entry
	# providing interactive crosshairs to read individual plot values

	my $pl = PDL::Graphics::PLplot->new( DEV => "wxwidgets");

=for html
<center><img WIDTH=400 src="PLplot/w03.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w03.pl.html>w03.pl highlighted  source code</a></center>
<center> <a href=PLplot/w03.pl> w03.pl text source code</a></center><hr><p>   


=head2 setting the DEV and FILE options, and using the aliased option for new()

  There are 2 ways to call new(), and the aliased module makes the syntax a bit easier.
  
  The conventional way:
      use PDL::Graphics::PLplot;
      my $pl = PDL::Graphics::PLplot->new( DEV => "xwin");
      
  The aliased way:    
      use aliased 'PDL::Graphics::PLplot'; 
      my $pl = PLplot->new( DEV => "xwin" );


  Specify the DEV in your call to new. 
      For output to a window:
         -- option DEV must be set to xwin, wxwidgets, or similar
  For output to a file:
         -- option DEV must be set to xfig, svg, pscairo, or similar
         -- option FILE must give the output file's name
  For output to a memory buffer:
         -- option DEV must be set to mem or memcairo
         --option MEM must be passed a piddle where the results will be plot


=head2 Outputting postscript

	# Save the image to a postscript file
	my $pl = PDL::Graphics::PLplot->new(
               DEV => 'ps'
             , FILE => 'myfile.eps'
        );


=head2 Tools for plotting points

You can plot lines, symbols, or both by using the PLOTTYPE
option. You specify error bars in x and y by passing a scalar or a
piddle with those errors to XERRORBAR and YERRORBAR.

   -- PLOTTYPE => LINE plots data as lines (default)
   -- PLOTTYPE => POINTS plots data as points
   -- PLOTTYPE => LINEPOINTS plots data as lines and points
   -- PLplot's built in error-bars can plot asymmetric error bars,
      but the high-level PDL bindings do not support this.

To set the symbol type and size, use the SYMBOL and SYMBOLSIZE options.

  --  Symbol sizes are measured as multiples of the default size
  -- Symbol sizes can be fractional, such as 0.7 or 4.5
  -- Symbols are identified by their number
 

=head2 A C<Symbols> example

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use PDL::Graphics::PLplot;

  # Generate a time series
  my $time = sequence(100)/10;
  my $sinewave = 5 * sin($time);

  # Save the image to a postscript file

  my $pl = PDL::Graphics::PLplot->new(
       DEV => 'pscairo'
     , FILE => 'Symbols.eps'
  );

  # Plot the time series as points
  $pl->xyplot($time, $sinewave
          , PLOTTYPE => 'POINTS'
          , SYMBOL       => 843
          , YERRORBAR => grandom($time)/2
     );

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w04.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w04.pl.html>w04.pl highlighted  source code</a></center>
<center> <a href=PLplot/w04.pl> w04.pl text source code</a></center><hr><p>   


=head2 Plotting multiple curves

Depending on what you want, there are at least five ways to plot multiple curves.

    -- plot a multidimensional piddle
    -- call xyplot multiple times
    -- use stripplots
    -- specify SUBPAGES in the constructor
    -- create insets using the VIEWPORT option


=head3 Plotting multiple curves with a multi-dimensional piddle

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';

   # Generate a time series
   my $time = sequence(100)/10;
   my $sinewave = 5 * sin($time);
   my $cosinewave = 4 * cos($time);
   my $toplot = cat($sinewave, $cosinewave);

   # Save the image to a postscript file

   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'Multidimensional.eps'
    );


  # Plot the time series
  $pl->xyplot($time, $toplot);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w05.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w05.pl.html>w05.pl highlighted  source code</a></center>
<center> <a href=PLplot/w05.pl> w05.pl text source code</a></center><hr><p>   

=head3 Colorizing multiple data sets

Use color to differentiate different data sets:

   -- For multidimensional piddles, plot as POINTS and use the
      COLORMAP and PALETTE options.
   -- For multiple calls to xyplot, use POINTS, COLORMAP, and
      PALETTE, or use COLOR option.

The COLORMAP option lets you specify a third value for each
(x, y) pair, making it (x, y, colorval).

Which color is associated with the minimum colorval? Which
color is associated with the maximum value? All of these are set
with the PALETTE.

Valid PALETTEs include:

  RAINBOW - from red to violet through the spectrum
  REVERSERAINBOW - violet through red
  GREYSCALE - from black to white via grey
  REVERSEGREYSCALE - from white to black via grey
  GREENRED - from green to red
  REDGREEN - from red to green

Note:

    --  the default palette is not named
    --  this only works when plotting points, not lines or error bars

A multi-colored multi-curve plot

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';

   my $pl = PLplot->new(
     DEV => 'pscairo',
     FILE => 'Multidimensional2.eps');

   # Generate a time series and phase offset
   my $time = sequence(100)/10;
   my $phi = zeroes(4)->xlinvals(0, 3)->transpose;

   my $sinewaves = 5*sin($time + $phi);
   # Plot the time series and phi color key
   $pl->xyplot($time, $sinewaves,
     PLOTTYPE => 'POINTS',
     COLORMAP => $phi,
     TITLE => 'sin(x + #gf)');

   $pl->colorkey($phi, 'v',
      TITLE => '#gf',
      VIEWPORT => [0.93, 0.96, 0.15, 0.85]);
   $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w06.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w06.pl.html>w06.pl highlighted  source code</a></center>
<center> <a href=PLplot/w06.pl> w06.pl text source code</a></center><hr><p>   


=head3 Plotting multiple curves with differently colored calls to C<xyplot>

An alternative to plotting a multi-dimensional piddle, you can plot multiple
curves by multiple calls to xyplot, specifying  a different color for each plot.

Legal colors are:

    BLACK       GREEN         WHEAT
    BLUE        RED           AQUAMARINE
    GREY        BLUEVIOLET    YELLOW
    PINK        BROWN         CYAN
    TURQUOISE   MAGENTA       SALMON
    WHITE       ROYALBLUE     DEEPSKYBLUE
    VIOLET      STEELBLUE1    DEEPPINK
    MAGENTA     DARKORCHID1   PALEVIOLETRED2
    TURQUOISE1  LIGHTSEAGREEN SKYBLUE
    FORESTGREEN CHARTREUSE3   GOLD2
    SIENNA1     CORAL         HOTPINK
    LIGHTCORAL  LIGHTPINK1    LIGHTGOLDENROD

Notes:

   --  Curve clipping - the first plot sets the plotting boundaries
        and later plots fall outside of those boundaries
   --  Changing `current' color - the first plot sets the `current'
        color and the second does not specify a color
   --  PLplots has a discrete color limit of 16, including foreground and background color.

When plotting multiple curves, the first plot sets the boundaries, and
can result in subsequent plots being clipped. The obvious solution, is
to plot your curve with largest values first. To force a separate color
from the first set default color, always specify the colors in xyplot. 

=head3 A multiple curve with C<xyplot>

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  # Generate a time series
  my $time = sequence(100)/10;
  my $sinewave = 5 * sin($time);
  my $cosinewave = 4 * cos($time);

  # Save the image to a postscript file
  my $pl = PLplot->new(
        DEV => 'pscairo', 
        FILE => 'Multiple curves.eps'
   );

  # Plot the sine in black, cosine in red
  $pl->xyplot($time, $sinewave);
  $pl->xyplot($time, $cosinewave , COLOR => 'RED');

  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w07.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w07.pl.html>w07.pl highlighted  source code</a></center>
<center> <a href=PLplot/w07.pl> w07.pl text source code</a></center><hr><p>   


=head3 Solving curve clipping on multiple xyplots with the C<BOX> option

=for html
<center><img WIDTH=400 src="PLplot/w08a.pl.800.png"></center>
<center> Clipped data </center> <p>   

When you have multiple xyplots, with widely separated values, you can
use the C<xyplot BOX> option to prevent clipping.

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  # Generate a time series
  my $time = sequence(100)/10;
  my $sinewave = 5 * sin($time);
  my $cosinewave = 6 * cos($time);

  # Save the image to a postscript file
  my $pl = PLplot->new(
      DEV => 'pscairo',
     FILE => 'Multiple curves3.eps'
  );

  # Plot the sine with full bounds
  $pl->xyplot($time, $sinewave,
      BOX => [$time->minmax, $cosinewave->minmax]);

  # Plot the cosine in red
  $pl->xyplot($time, $cosinewave , COLOR => 'RED');

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w08.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w08.pl.html>w08.pl highlighted  source code</a></center>
<center> <a href=PLplot/w08.pl> w08.pl text source code</a></center><hr><p>   


=head3 Plotting multiple curves with C<stripplot>

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  # Save the image to a postscript file
  my $pl = PLplot->new(
      DEV => 'pscairo',
      FILE => 'stripplots.eps'
   );

  # Generate a time series
  my $time = sequence(100)/10;

  # Make stripplots with the
  #      different time series
  $pl->stripplots($time,
       [sin($time), cos($time)],
       XLAB => 'x',
       YLAB => ['sine', 'cosine'],
       COLOR => ['BLUE', 'RED'],
       TITLE => 'Sine and Cosine'
   );

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w09.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w09.pl.html>w09.pl highlighted  source code</a></center>
<center> <a href=PLplot/w09.pl> w09.pl text source code</a></center><hr><p>   


=head3 Stripplots and reading C<DATA> with C<rcols>

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use PDL::Graphics::PLplot;

  my ($t, $data) = rcols(*DATA, 0, []);

  my $pl = PDL::Graphics::PLplot->new( DEV => "xwin" );

  # Make stripplots with the different time series
  # notice data must be transposed                        
  $pl->stripplots($t, $data->transpose);                  
  $pl->close;                                             
  __DATA__                                                
  #    t      x1     x2     x3            
       1      4      6     -1             
       2      3      9      3             
       3      2      8      7             
       3     -1      4     10
       5      1      2      6             
       6      5     -1      5

=for html
<center><img WIDTH=400 src="PLplot/w10.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w10.pl.html>w10.pl highlighted  source code</a></center>
<center> <a href=PLplot/w10.pl> w10.pl text source code</a></center><hr><p>   

=head3 Multiple plots with C<SUBPAGE>

When you create your PLplot object, you can carve the canvas
into immutable subpages.
   my $pl = PDL::Graphics::PLplot->new(
         # ...
         , SUBPAGES => [$nx, $ny]
     );

For example:

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  # Generate a time series 
  my $time = sequence(100)/10;

  # Save the image to a postscript file
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'subpages.eps',
       SUBPAGES => [2,2]);

  # Plot the time series
  $pl->xyplot($time, sin($time), TITLE => 'Sine');

  $pl->xyplot($time, cos($time), TITLE => 'Cosine',
            SUBPAGE => 0);

  $pl->xyplot($time, tan($time), TITLE => 'Tangent',
            SUBPAGE => 4);

  $pl->xyplot($time, $time**2, TITLE => 'Squared',
            SUBPAGE => 3);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w11.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w11.pl.html>w11.pl highlighted  source code</a></center>
<center> <a href=PLplot/w11.pl> w11.pl text source code</a></center><hr><p>   


=head2 Boxes and Viewports

=head3 Using Insets

ometimes you want a small inset in one of the corners of your plot. If you
ant to do this you should:

  --  Specify the VIEWPORT
  --  Specify the BOX
  --  Use a smaller CHARSIZE
  --  If the underlying plot has a title, you should probably undefine it
  --  Undefine or change the XLAB and YLAB unless you want to use the
        values from the underlying plot


  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL::Graphics::PLplot; 
  use PDL;
  use PDL::NiceSlice;

  # Generate a noisy time series
  my $time = sequence(1000) /10;
  my $sinewave = 1 * sin($time) + grandom($time) / 3;

  # Save the image to a postscript file
  my $pl = PDL::Graphics::PLplot->new( DEV => 'pscairo', FILE => 'inset.eps');

  # Plot subset as the main plot
  $pl->xyplot($time(0:65), $sinewave(0:65), TITLE => 'Noisy Pendulum',
          YLAB => 'Displacement d [m]', XLAB => 'Time t [s]');

  # Plot full data set as inset
  $pl->xyplot($time, $sinewave,
     TITLE       => undef,
     VIEWPORT => [0.525, 0.825, 0.525, 0.775],
     BOX         => [$time->minmax, $sinewave->minmax],
     CHARSIZE => 0.6
    );
  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w12.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w12.pl.html>w12.pl highlighted  source code</a></center>
<center> <a href=PLplot/w12.pl> w12.pl text source code</a></center><hr><p>   

=head2 Basics of viewports 

PLplot has three distinct measurements for your plot at any point:

    -- the plotting surface's dimensions
    -- the viewport's relative extent
    -- the `natural' coordinates within the viewport

=head2 Surface dimensions

The dimensions of the canvas or surface that you are using can
be specified in the constructor (and cannot be changed later):

   my $pl = PDL::Graphics::PLplot->new(
           # other options...
           PAGESIZE => [$width, $height]
          # other options...
      );

These are measured either in pixels or milimeters depending on
whether the underlying format is a raster or vector format.

=head2 Viewport positioning

The viewport carves out a chunk of space on the canvas for
plotting and can be changed with each plotting function.

    $pl->xyplot($x, $y
             # other options
             , VIEWPORT => [$xmin, $xmax, $ymin, $ymax]
             # other options
         );
    # Plot on right half of the page
    VIEWPORT => [0.5, 1, 0, 1]
    # Plot in upper half of the page
    VIEWPORT => [0, 1, 0, 0.5]
    # Vertically centered, horizontally offset
    VIEWPORT => [0.5, 0.7, 0.4, 0.6]

Viewport values are fractions of the full page (or sub-page) width
all four values should be a number between 0 and 1.

=head3 The clipping box

If the viewport indicates the chunk of space you will be graphing
on, the clipping box indicates the coordinates within that chunk
of space.

    $pl->xyplot($x, $y
              # other options...
              , BOX => [$xmin, $xmax, $ymin, $ymax]
              # other options...
         );
   
     # x runs from 0 to 10, y from -8 to 8:
     BOX => [0, 10, -8, 8]
     # piddles have the minmax method:
     BOX => [$x pdl->minmax, $y pdl->minmax]

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.

=head3 Page size

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $y = $x**2;

  # Set a custom page size
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 2.eps',
       BACKGROUND => 'SKYBLUE',
       PAGESIZE => [360, 240]
    );

  # Plot a quadratic function:
  $pl->xyplot($x, $y, YLAB => 'y', XLAB => 'x');

  $pl->close  

=for html
<center><img WIDTH=400 src="PLplot/w13.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w13.pl.html>w13.pl highlighted  source code</a></center>
<center> <a href=PLplot/w13.pl> w13.pl text source code</a></center><hr><p>   

=head3 Viewport upper right

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $y = $x**2;

  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 3.eps',
       BACKGROUND => 'SKYBLUE'
  );

  # Put the plot in the upper right:
  $pl->xyplot($x, $y,
       YLAB => 'y',
       XLAB => 'x',
       VIEWPORT => [0.5, 0.9, 0.6, 0.8]
       );

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w14.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w14.pl.html>w14.pl highlighted  source code</a></center>
<center> <a href=PLplot/w14.pl> w14.pl text source code</a></center><hr><p>   

=head3 Viewport centered

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $y = $x**2;
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 4.eps',
       BACKGROUND => 'SKYBLUE'
      );

  # Center the plot
  $pl->xyplot($x, $y,
      YLAB => 'y', XLAB => 'x',
      VIEWPORT => [0.3, 0.7, 0.3, 0.7]
      );

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w15.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w15.pl.html>w15.pl highlighted  source code</a></center>
<center> <a href=PLplot/w15.pl> w15.pl text source code</a></center><hr><p>   

=head3 Viewport extreme bounds

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $y = $x**2;
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 5.eps',
       BACKGROUND => 'SKYBLUE'
      );

  # Try extreme bounds for the viewport
  $pl->xyplot($x, $y ,
       YLAB => 'y',
       XLAB => 'x',
       VIEWPORT  => [0, 1, 0.3, 1]
       );

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w16.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w16.pl.html>w16.pl highlighted  source code</a></center>
<center> <a href=PLplot/w16.pl> w16.pl text source code</a></center><hr><p>   


=head3 Viewport multiple plots

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $y = $x**2;
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 6.eps',
       BACKGROUND => 'SKYBLUE');

  # Big plot on left
  $pl->xyplot($x, $y, VIEWPORT
       => [0.1, 0.6, 0.1, 0.8]);
  
  # Medium plot on upper right
  $pl->xyplot($x, $y, VIEWPORT
       => [0.5, 0.9, 0.6, 0.9]);
  
  # Small plot on lower right
  $pl->xyplot($x, $y, VIEWPORT
       => [0.7, 0.9, 0.1, 0.4]);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w17.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w17.pl.html>w17.pl highlighted  source code</a></center>
<center> <a href=PLplot/w17.pl> w17.pl text source code</a></center><hr><p>   


=head3 The basic box

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 7.eps',
       BACKGROUND => 'SKYBLUE');

  # Sine wave on top
  $pl->xyplot($x, sin($x),
     VIEWPORT => [0.1, 0.9, 0.55, 0.9]);

  # Quadratic on bottom
  # BOX is inherited from first plot
  $pl->xyplot($x, $x**2,
     VIEWPORT => [0.1, 0.9, 0.1, 0.45]);

  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w18.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w18.pl.html>w18.pl highlighted  source code</a></center>
<center> <a href=PLplot/w18.pl> w18.pl text source code</a></center><hr><p>   

=head3 The tweaked box

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 8.eps',
       BACKGROUND => 'SKYBLUE');

  # Sine wave on top
   $pl->xyplot($x, sin($x),
       VIEWPORT => [0.1, 0.9, 0.55, 0.9]);

  # Quadratic on bottom
   $pl->xyplot($x, $x**2,
       VIEWPORT => [0.1, 0.9, 0.1, 0.45],
       BOX => [-3, 3, 0, 9]);

  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w19.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w19.pl.html>w19.pl highlighted  source code</a></center>
<center> <a href=PLplot/w19.pl> w19.pl text source code</a></center><hr><p>   


=head3 Box with 2 plots

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 9.eps',
       BACKGROUND => 'SKYBLUE');

  # Sine wave
  $pl->xyplot($x, sin($x));

  # Plotting a quadratic on top works
  # but the bounds are not good
  $pl->xyplot($x, $x**2);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w20.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w20.pl.html>w20.pl highlighted  source code</a></center>
<center> <a href=PLplot/w20.pl> w20.pl text source code</a></center><hr><p>   


=head3 Multiple plots, changing the box within a single viewport

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $x = zeroes(20)->xlinvals(-3, 3);
  my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'box example 10.eps',
       BACKGROUND => 'SKYBLUE');

  # Sine wave
  $pl->xyplot($x, sin($x));

  # Changing the box for the quadratic
  # does not work - bad y ticks
  $pl->xyplot($x, $x**2,
       BOX => [-3, 3, 0, 9]);

  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w21.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w21.pl.html>w21.pl highlighted  source code</a></center>
<center> <a href=PLplot/w21.pl> w21.pl text source code</a></center><hr><p>   


=head3 Box and viewport summary

For multiple plots on the same viewport, set the box with the first call to xyplot For non-overlapping plots (on different viewports), specify the box as necessary The viewport specifies the extent of the plotting region; tick labels, axis labels, and titles are drawn outside the viewport

=head2 Other types of plot

=head3 Shadeplot 

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';
   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'shadeplot3.eps');
   # Define z = sin(x) + cos(y), a 2D piddle:
   my $x=zeroes(51)->xlinvals(-10, 10);
   my $y=zeroes(51)->xlinvals(1, 7);
   my $z=sin($x) + cos($y->transpose);
   # Make a shade plot with 15 color steps:
   $pl->shadeplot($z, 15,
       BOX => [$x->minmax, $y->minmax],
       XLAB => 'x', YLAB => 'y',
       TITLE => 'Egg Carton');
  # Add a 'vertical' color key:
  $pl->colorkey($z, 'v', VIEWPORT => [0.93, 0.96, 0.15, 0.85],
           XLAB => '', YLAB => '', TITLE => 'depth');
  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w22.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w22.pl.html>w22.pl highlighted  source code</a></center>
<center> <a href=PLplot/w22.pl> w22.pl text source code</a></center><hr><p>   

=head3 Histogram 

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';
  
   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'histogram.eps');
  
   # Generate some data:
   my $data = grandom(1000);
  
   # Make a histogram of that data in 20 bins:
   $pl->histogram($data, 20);
  
   $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w23.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w23.pl.html>w23.pl highlighted  source code</a></center>
<center> <a href=PLplot/w23.pl> w23.pl text source code</a></center><hr><p>   

=head3 Histogram height

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';

   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'histogram2.eps');

   # Generate some data:
   my $data = grandom(1000);

   # Get approximate binning:
   my $nbins = 20;
   my $binwidth =  ($data->max-$data->min) / $nbins;

   my ($x, $y) = hist($data , $data->minmax, $binwidth);

   # Make a histogram of that data in 20 bins:
   my $fudgefactor = 1.1;

   $pl->histogram($data, $nbins,
           BOX => [$x->minmax, 0, $y->max * $fudgefactor]);

   $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w24.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w24.pl.html>w24.pl highlighted  source code</a></center>
<center> <a href=PLplot/w24.pl> w24.pl text source code</a></center><hr><p>   

=head3 Bargraph

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';
  
   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'bargraph.eps');
  
   # Generate some data:
   my @colors = qw(red orange yellow green blue purple);
   my $votes = random(scalar(@colors));
  
   # Normalize the votes
   $votes /= $votes->sum;
  
   # Make a barchart of the votes.
   $pl->bargraph(\@colors, $votes);
  
   $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w25.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w25.pl.html>w25.pl highlighted  source code</a></center>
<center> <a href=PLplot/w25.pl> w25.pl text source code</a></center><hr><p>   

=head3 Bargraph color and bar height

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';
  
   my $pl = PLplot->new(
       DEV => 'pscairo',
       FILE => 'bargraph2.eps');
  
   # Generate some data:
   my @colors = qw(red orange yellow green blue purple);
   my $votes = random(scalar(@colors));
  
   # Normalize the votes
   $votes /= $votes->sum;
  
   # Make a barchart of the votes.
   $pl->bargraph(\@colors, $votes,
        COLOR => 'BLUE',
        BOX => [0, scalar(@colors), 0, 1.1 * $votes->max]
     );
  
  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w26.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w26.pl.html>w26.pl highlighted  source code</a></center>
<center> <a href=PLplot/w26.pl> w26.pl text source code</a></center><hr><p>   

=head3 Bargraph with labelling 

   #!/usr/bin/perl
   use strict;
   use warnings;
   use PDL;
   use aliased 'PDL::Graphics::PLplot';

   my $pl = PLplot->new(
         DEV => 'pscairo',
         FILE => 'bargraph3.eps');

   # voting on letters:
   my @letters = ('a' .. 'z');
   my $votes = random(0 + @letters);

   # Normalize the votes
   $votes /= $votes->sum;

   # Make a barchart of the votes.
   $pl->bargraph(\@letters, $votes,
         COLOR => 'LIGHTGOLDENROD',
         BOX => [0, scalar(@letters) , 0, 1.1 * $votes->max],
         MAXBARLABELS => 10
     );

$pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w27.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w27.pl.html>w27.pl highlighted  source code</a></center>
<center> <a href=PLplot/w27.pl> w27.pl text source code</a></center><hr><p>   


=head2 Using the MEM device 

Use the MEM device to:
  --  load an image and plot over that image
  --  plot to a custom windowing device
  --  animated plots

The way the MEM device works, is that it needs an
RGB or RGBA (RGB with alpha transparency) buffer
to write on top of.

=head3 Creating a C<MEM> memory buffer

There are 2 drivers which handle the MEM device, mem and memcairo.
mem is for plain RGB. memcairo can handle transparency values. 

  use PDL;
  ## creating the mem device buffer ##
  
  # the mem device
  # Allocate the buffer for plain rgb
  my $buffer = zeroes(byte, 3, $width, $height);
  
  # Create the PLplot object
  my $pl = PDL::Graphics::PLplot->new(
                 DEV => 'mem',
                 MEM => $buffer
          );                                            
  
  ## For the memcairo device which handles tranparencies ##
  
  # Allocate the buffer                                   
  my $buffer = zeroes(byte, 4, $width, $height);          
  
  # Create the PLplot object
  my $pl = PDL::Graphics::PLplot->new(
                 DEV => 'memcairo',
                 MEM => $buffer
          );


=head3 Plotting over an image with the C<MEM> device

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';
  use PDL::IO::Pic;

  # Load an image
  # (has dims 3 x width x height)
  my $pic = rpic('earth.jpg');


  # Flip the y axis
  $pic = $pic->slice(':,:,-1:0:-1');
  # Whiten the image a bit
  $pic = 127 + $pic / 2;

  my $pl = PLplot->new( DEV => 'mem',
                        MEM => $pic);

  # Plot a quadratic curve over the image
  my $x=zeroes(51)->xlinvals(-10, 10);
  $pl->xyplot($x, $x**2);
  $pl->close;

  # flip the y axis back and save the image
  $pic = $pic->slice(':,:,-1:0:-1');
  wpic($pic, 'earth_plot.png');

=for html
<center><img WIDTH=400 src="PLplot/w29.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w29.pl.html>w29.pl highlighted  source code</a></center>
<center> <a href=PLplot/w29.pl> w29.pl text source code</a></center><hr><p>   


=head2 B<Functional programming style examples>

This section uses the functional programming style of the original C
library examples.


=head3 Simple line plot and multiple windows demo x01

=for html
<center><img WIDTH=400 src="PLplot/x01.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x01.pl.html>x01.pl highlighted  source code</a></center>
<center> <a href=PLplot/x01.pl> x01.pl text source code</a></center><hr><p>   


=head3 Multiple window and color map 0 demo x02

=for html
<center><img WIDTH=400 src="PLplot/x02.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x02.pl.html>x02.pl highlighted  source code</a></center>
<center> <a href=PLplot/x02.pl> x02.pl text source code</a></center><hr><p>   

=head3 Polar plot demo x03

=for html
<center><img WIDTH=400 src="PLplot/x03.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x03.pl.html>x03.pl highlighted  source code</a></center>
<center> <a href=PLplot/x03.pl> x03.pl text source code</a></center><hr><p>   

=head3 Log plot demo x04

=for html
<center><img WIDTH=400 src="PLplot/x04.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x04.pl.html>x04.pl highlighted  source code</a></center>
<center> <a href=PLplot/x04.pl> x04.pl text source code</a></center><hr><p>   


=head3 Histogram demo x05

=for html
<center><img WIDTH=400 src="PLplot/x05.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x05.pl.html>x05.pl highlighted  source code</a></center>
<center> <a href=PLplot/x05.pl> x05.pl text source code</a></center><hr><p>   

=head3 Font demo x06

=for html
<center><img WIDTH=400 src="PLplot/x06.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x06.pl.html>x06.pl highlighted  source code</a></center>
<center> <a href=PLplot/x06.pl> x06.pl text source code</a></center><hr><p>   

=head3 Font demo x07

=for html
<center><img WIDTH=400 src="PLplot/x07.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x07.pl.html>x07.pl highlighted  source code</a></center>
<center> <a href=PLplot/x07.pl> x07.pl text source code</a></center><hr><p>   

=head3 3-d plot demo x08

=for html
<center><img WIDTH=400 src="PLplot/x08.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x08.pl.html>x08.pl highlighted  source code</a></center>
<center> <a href=PLplot/x08.pl> x08.pl text source code</a></center><hr><p>   

=head3 Contour plot demo x09

=for html
<center><img WIDTH=400 src="PLplot/x09.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x09.pl.html>x09.pl highlighted  source code</a></center>
<center> <a href=PLplot/x09.pl> x09.pl text source code</a></center><hr><p>   

=head3 Window positioning demo x10

=for html
<center><img WIDTH=400 src="PLplot/x10.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x10.pl.html>x10.pl highlighted  source code</a></center>
<center> <a href=PLplot/x10.pl> x10.pl text source code</a></center><hr><p>   


=head3 Mesh plot demo x11

=for html
<center><img WIDTH=400 src="PLplot/x11.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x11.pl.html>x11.pl highlighted  source code</a></center>
<center> <a href=PLplot/x11.pl> x11.pl text source code</a></center><hr><p>   

=head3 Bar chart demo x12

=for html
<center><img WIDTH=400 src="PLplot/x12.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x12.pl.html>x12.pl highlighted  source code</a></center>
<center> <a href=PLplot/x12.pl> x12.pl text source code</a></center><hr><p>   


=head3 simple pie chart x13

=for html
<center><img WIDTH=400 src="PLplot/x13.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x13.pl.html>x13.pl highlighted  source code</a></center>
<center> <a href=PLplot/x13.pl> x13.pl text source code</a></center><hr><p>   


=head3 Shade plot demo x15

=for html
<center><img WIDTH=400 src="PLplot/x15.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x15.pl.html>x15.pl highlighted  source code</a></center>
<center> <a href=PLplot/x15.pl> x15.pl text source code</a></center><hr><p>   


=head3 plshade demo, using color fill x16

=for html
<center><img WIDTH=400 src="PLplot/x16.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x16.pl.html>x16.pl highlighted  source code</a></center>
<center> <a href=PLplot/x16.pl> x16.pl text source code</a></center><hr><p>   

=head3 A simple stripchart with four pens x17

=for html
<center><img WIDTH=400 src="PLplot/x17.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x17.pl.html>x17.pl highlighted  source code</a></center>
<center> <a href=PLplot/x17.pl> x17.pl text source code</a></center><hr><p>   

=head3 3-d line and point plot demo x18

=for html
<center><img WIDTH=400 src="PLplot/x18.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x18.pl.html>x18.pl highlighted  source code</a></center>
<center> <a href=PLplot/x18.pl> x18.pl text source code</a></center><hr><p>   

=head3 Backdrop plotting of world, US maps. x19

=for html
<center><img WIDTH=400 src="PLplot/x19.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x19.pl.html>x19.pl highlighted  source code</a></center>
<center> <a href=PLplot/x19.pl> x19.pl text source code</a></center><hr><p>   

=head3 Grid data demo x21

=for html
<center><img WIDTH=400 src="PLplot/x21.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x21.pl.html>x21.pl highlighted  source code</a></center>
<center> <a href=PLplot/x21.pl> x21.pl text source code</a></center><hr><p>   


=head3 Simple vector plot x22

=for html
<center><img WIDTH=400 src="PLplot/x22.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x22.pl.html>x22.pl highlighted  source code</a></center>
<center> <a href=PLplot/x22.pl> x22.pl text source code</a></center><hr><p>   


=head3 Displays Greek letters and mathematically interesting Unicode ranges x23

=for html
<center><img WIDTH=400 src="PLplot/x23.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x23.pl.html>x23.pl highlighted  source code</a></center>
<center> <a href=PLplot/x23.pl> x23.pl text source code</a></center><hr><p>   


=head3 Unicode Pace Flag x24

=for html
<center><img WIDTH=400 src="PLplot/x24.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x24.pl.html>x24.pl highlighted  source code</a></center>
<center> <a href=PLplot/x24.pl> x24.pl text source code</a></center><hr><p>   

=head3 Drawing polygons x25

=for html
<center><img WIDTH=400 src="PLplot/x25.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x25.pl.html>x25.pl highlighted  source code</a></center>
<center> <a href=PLplot/x25.pl> x25.pl text source code</a></center><hr><p>   

=head3 Frequency Amplitude and Phase x26

=for html
<center><img WIDTH=400 src="PLplot/x26.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x26.pl.html>x26.pl highlighted  source code</a></center>
<center> <a href=PLplot/x26.pl> x26.pl text source code</a></center><hr><p>   

=head3 Spirograph curves - epitrochoids, cycolids, roulettes x27

=for html
<center><img WIDTH=400 src="PLplot/x27.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x27.pl.html>x27.pl highlighted  source code</a></center>
<center> <a href=PLplot/x27.pl> x27.pl text source code</a></center><hr><p>   

=head3 plmtex3, plptex3 demo x28

=for html
<center><img WIDTH=400 src="PLplot/x28.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x28.pl.html>x28.pl highlighted  source code</a></center>
<center> <a href=PLplot/x28.pl> x28.pl text source code</a></center><hr><p>   

=head3 Plots using date / time formatting for axes x29

=for html
<center><img WIDTH=400 src="PLplot/x29.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x29.pl.html>x29.pl highlighted  source code</a></center>
<center> <a href=PLplot/x29.pl> x29.pl text source code</a></center><hr><p>   


=head3 Alpha color values demonstration  x30

=for html
<center><img WIDTH=400 src="PLplot/x30.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x30.pl.html>x30.pl highlighted  source code</a></center>
<center> <a href=PLplot/x30.pl> x30.pl text source code</a></center><hr><p>   


=head3 Using C<pllegend> including unicode symbols x33

=for html
<center><img WIDTH=400 src="PLplot/x33.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/x33.pl.html>x33.pl highlighted  source code</a></center>
<center> <a href=PLplot/x33.pl> x33.pl text source code</a></center><hr><p>   


=head2 Typesetting, greek letters, symbols

Use escape sequences to insert superscripts, subscripts, Greek
letters, etc.

    #u - superscript until the next #d
    #d - subscript until the next #u
    #- - toggle underline mode
    #+ - toggle overline mode
    #fn - switch to normal (sans-serif) font
    #fr - switch to Roman (serif) font
    #fi - switch to italic font
    #fs - switch to script font

   # Use greek symbol rho for density:
       $pl->xyplot($radius, $density, 
       YLAB => 'density #gr'
        # ...
       );

Unicode is supported.

=for html
<center><img WIDTH=400 src="PLplot/w30a.pl.800.png"></center><hr><p>   

=head3 A basic typsetting example

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  # Generate a time series
  my $time = sequence(100)/10;
  my $sinewave = 5 * sin($time);

  # Create the PLplot object:
  my $pl = PLplot->new(
        DEV => 'pscairo',
        FILE => 'Typesetting.eps');

  # Plot the time series
  $pl->xyplot($time, $sinewave,
        XLAB => '#fi time #fn [Hz#u-1#d]',
        YLAB => '#fiposition#fn [cm]',
        TITLE => '#frMass on Spring'
      );

  # Close the PLplot object to finalize
  $pl->close;


=for html
<center><img WIDTH=400 src="PLplot/w30.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w30.pl.html>w30.pl highlighted  source code</a></center>
<center> <a href=PLplot/w30.pl> w30.pl text source code</a></center><hr><p>   

=head3 psfrag

For LATEX typsetting, post-process eps images with psfrag.

   --  replaces simple strings with any valid LATEX text.
   --  ensures consistent fonts for both images and documents
   --  Do not use the pscairo device. Use ps or psc.


=head2 annotations and TEXTPOSITION 

To add text to a plot, use the text method, specifying the
TEXTPOSITION option. The TEXTPOSITION takes either four or
five arguments. The four-argument form places text outside the
viewport along one of its edges:

   $pl->text($string, TEXTPOSITION => [$side, $disp, $pos, $just]);

$side is one of 't', 'b', 'l', or 'r' indicating the top, bottom, left,
or right edge

$disp is the number of character heights out from the edge

$pos is the position of the string's reference point along the
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

The five-argument form places the text within the viewport at an
arbitrary position and slope:

  $pl->text($string, TEXTPOSITION => [$x, $y, $dx, $dy, $just]);

$x, $y are the location of the string's reference point within the
clipping box

$dx, $dy together indicate the slope along which the text is
drawn

$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

=head3 TEXTPOSITION 3 argument form

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $pl = PLplot->new(
           DEV => 'pscairo',
           FILE => 'text1.eps');

  my $x = zeroes(100)->xlinvals(-3,3);
  my $y = $x**2;
  $pl->xyplot($x, $y);

  $pl->setparm(CHARSIZE => 1.2);
  # x label on the lower right
  $pl->text('Position x [m]',
           TEXTPOSITION => ['b', 3, 1, 1]);

  # y label on the upper left
  $pl->text('Potential Energy V [J]',
           TEXTPOSITION => ['l', 3.5, 1, 1]);

  # title at the center top
  $pl->text('Harmonic Oscillator',
           CHARSIZE => 2.5,
           TEXTPOSITION => ['t', 1.5, 0.5, 0.5]);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w31.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w31.pl.html>w31.pl highlighted  source code</a></center>
<center> <a href=PLplot/w31.pl> w31.pl text source code</a></center><hr><p>   

=head3 TEXTPOSITION 4 argument form

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use aliased 'PDL::Graphics::PLplot';

  my $pl = PLplot->new(
         DEV => 'pscairo',
         FILE => 'text2.eps');

  # Plot a quadratic
  my $x = zeroes(100)->xlinvals(-3,3);
  my $y = $x**2;

  $pl->xyplot($x, $y, TITLE => 'SHO',
         XLAB => 'Position x [m]',
         YLAB => 'Potential V [J]');

  # annotate negative slope at (-2, 4)
  $pl->text('Slope is negative',
           TEXTPOSITION => [-1.8, 4.1, 1, -4, 0.5]);

  # annotate positive slope at (2, 4)
  $pl->text('Slope is positive',
           TEXTPOSITION => [1.9, 3.9, 10, 40, 1]);

  $pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w32.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w32.pl.html>w32.pl highlighted  source code</a></center>
<center> <a href=PLplot/w32.pl> w32.pl text source code</a></center><hr><p>   

=head2 Legends

PLplot does not have a command to create legends. We must make them
ourselves. Legends are only necessary when plotting discrete data sets.
If possible, use color keys instead of constructing legends by hand.

  #!/usr/bin/perl
  use strict;
  use warnings;
  use PDL;
  use PDL::Graphics::PLplot;

  my $pl = PDL::Graphics::PLplot->new(
                DEV => 'pscairo',
                FILE => 'legend.eps');


  my $x = zeroes(100)->xlinvals(-1.2, 1.2);
  my @colors = qw(BLACK GREEN BLUE);
  my @labels = qw(Linear Quadratic Cubic);
  my $legend_x = pdl(0.3, 0.5);
  my $legend_y = -0.5;

  # Plot linear, quadratic, and cubic curves with a legend
   for my $i (0..2) {

   $pl->xyplot($x, $x**($i+1), COLOR => $colors[$i]);

   $pl->xyplot($legend_x, pdl($legend_y, $legend_y),
           COLOR => $colors[$i]);

   $pl->text($labels[$i], COLOR => 'BLACK',
           TEXTPOSITION => [0.6, $legend_y, 1, 0, 0]);

   $legend_y -= 0.2;
  }

$pl->close;

=for html
<center><img WIDTH=400 src="PLplot/w33.pl.800.png"></center>
<center><a TARGET="_new" href=PLplot/w33.pl.html>w33.pl highlighted  source code</a></center>
<center> <a href=PLplot/w33.pl> w33.pl text source code</a></center><hr><p>   

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks