The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

LaTeX::PGF::Diagram2D - Perl extension for drawing 2D diagrams.

SYNOPSIS

  use LaTeX::PGF::Diagram2D;
  
  my $Uq = 1.0;
  my $Ri = 4.0;
  
  sub I($)
  {
    my $RL = shift;
    my $back = $Uq / ($Ri + $RL);
    return $back;
  }
  
  # 10 centimeters wide, 6 centimeters high 
  my $d = LaTeX::PGF::Diagram2D->new(10.0, 6.0);
  
  $d->set_font_size(12.0);
  
  # R (on the x axis) is in the range 0 ... 10
  $d->axis('b')->set_linear(0.0, 10.0)->set_grid_step(1.0)
               ->set_tic_step(1.0);
  # I (on the y axis) is in the range 0 ... 0,3
  $d->axis('l')->set_linear(0.0,  0.3)->set_grid_step(0.05)
               ->set_tic_step(0.1);
  
  my $p = $d->plot('b', 'l');
  $p->set_xy_fct(\&I);
  
  $d->write("test001a.pgf");

DESCRIPTION

The module can be used to draw 2D diagrams following DIN 461 (a german standard) for use with LaTeX. The output of the module is a *.pgf file. In your LaTeX source make sure to have

  \usepackage{pgf}

in the preamble. The *.pgf files can be used with both latex/dvips and pdflatex.

Use code like

  \begin{figure}%
  {\centering%
  \input{file.pgf}\caption{My caption}\label{blablablubb}%
  }%
  \end{figure}

to include the produced graphics.

EXPORT

None by default.

CLASSES

The following classes are involved:

LaTeX::PGF::Diagram2D

represents a diagram.

LaTeX::PGF::Diagram2D::Axis

represents one axis of the diagram.

LaTeX::PGF::Diagram2D::Plot

represents one item to plot (a function or a point set).

Methods

Constructor

LaTeX::PGF::Diagram2D->new(width, height)

creates a new diagram object. Width and height of the canvas are specified in centimeters.

Setup

set_font_size(size)

specifies the font size of the LaTeX document in point.

axis(name)

returns a reference to the LaTeX::PGF::Diagram2D::Axis object for the name. The name can be one of ``bottom'', ``left'', ``right'' or ``top'' or one of the abbreviations ``b'', ``l'', ``r'' or ``t''. The object reference can be used to invoke the setup methods for the axis, see LaTeX::PGF::Diagram2D::Axis.

Create plot objects

plot(xaxisname, yaxisname)

creates a new plot object and saves it to the diagram. A referernce to the LaTeX::PGF::Diagram2D::Plot object is returned, this reference can be used to configure the plot object, see LaTeX::PGF::Diagram2D::Plot.

copy_plot(plotobjectreference)

duplicates a plot object and returns the reference to the new object. This is useful if you want to print i.e. a point set with an interpolation curve, so your need one object for the curve and another one for the dots.

Additional graphics objects

label(xaxisname, yaxisname, x, y, text [, anchor ])

adds a text label. The axis names decide which axis the coordinates belong to. The optional anchor argument is ``left'', ``right'', ``top'', ``bottom'' or a comma-separated combination of a horizontal and a vertical position.

polyline(xaxisname, yaxisname, arrayreference)

creates a polyline object. The third parameter is a reference to an array containing the x- and y-coordinates for each point.

Output

write(filename)

writes the graphics to the named file. If the filename suffix is ``.tex'' an entire LaTeX file is written, a file containing a PGF image otherwise.

SEE ALSO

LaTeX::PGF::Diagram2D::Axis.pm LaTeX::PGF::Diagram2D::Label.pm LaTeX::PGF::Diagram2D::Plot.pm LaTeX::PGF::Diagram2D::Polyline.pm

AUTHOR

Dirk Krause, <krause@localdomain>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Dirk Krause

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.3 or, at your option, any later version of Perl 5 you may have available.