Dirk Krause
and 1 contributors


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


  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);
  # 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)
  # 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)
  my $p = $d->plot('b', 'l');


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


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

Use code like

  \input{file.pgf}\caption{My caption}\label{blablablubb}%

to include the produced graphics.


None by default.


The following classes are involved:


represents a diagram.


represents one axis of the diagram.


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



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

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



specifies the font size of the LaTeX document in point.


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.


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.



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.


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


Dirk Krause, <krause@localdomain>


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.