LaTeX-PGF-Diagram2D
view release on metacpan or search on metacpan
doc-src/diagram-en.tex view on Meta::CPAN
\ifpdf
\hypersetup{
pdftitle={LaTeX::PGF::Diagram2D 1.00},
pdfsubject={LaTeX::PGF::Diagram2D},
pdfauthor={Dipl.-Ing.~D.~Krause}
}
\fi
\newcommand{\includepgfimage}[2]{%
\begin{figure}%
{\centering%
\input{#1.pgf}\caption{#2}\label{fig:#1}%
}%
\end{figure}%
}
\begin{document}
\startofdocument
\section{Introduction}
The module plots 2D diagrams following the \textsc{din} 461 standard
for use with \LaTeX{}.
The diagrams can contain functions and/or data.
PGF files produced by the module can be used with both latex/dvips
and pdflatex.
Use code like
\begin{lstlisting}
\begin{figure}%
{\centering%
\input{xxx.pgf}\caption{Meine Bildunterschrift}\label{blabla}%
}%
\end{figure}%
\end{lstlisting}
to use a PGF file in your \LaTeX{} source.
In contrast to other plotting programs we specify the size of the
drawing grid, not the size of the entire image.
Bezier splines are used to draw the curve unless polylines are
required explicitly.
The module does not attempt to replace other mathematics and
plotting software, instead it is best used in combination
with
GnuPlot\footnote{\url{http://gnuplot.sourceforge.net}}
and
wxMaxima\footnote{\url{http://maxima.sourceforge.net}}.
\clearpage
\section{Tutorial}
\subsection[Function]{Example 1: Function plot}
\figimage{diagf003}{Example circuit}
In an electronic circuit as seen in figure~\vref{fig:diagf003}
we have a voltage source \(U_{\text{q}}=1\,\text{V}\) with an internal resistance
\(R_{i}=4\,\Omega\). For a variable load resistor
\(0\leq R_{\text{L}}\leq 10\,\Omega\) we want to print the current
\(I\) for each \(R_{\text{L}}\) value.
The formula
\begin{align*}I&=\frac{U_{\text{q}}}{R_{\text{L}}+R_{\text{i}}}\end{align*}
can be used to calculate \(I\).
For a first overview we use GnuPlot:
\begin{lstlisting}[language=GnuPlot]
Uq=1.0
Ri=4.0
set xrange [0:10.0]
plot Uq/(Ri+x) title "Strom"
\end{lstlisting}
The maximum current is \(\tfrac{1}{4}\,\text{A}\), so we use a grid with
of 10\,cm and a grid height of 6\,cm to show currents up to 0,3\,A.
\clearpage
\lstinputlisting[float,title={../examples/test001a.pl},language=Perl]{../examples/test001a.pl}
For the first plot we use the file ../examples/test001a.pl.
In line 3 we use the LaTeX::PGF::Diagram2D module.
The function \textit{I} calculates the current for a resistor value,
the resistor value is the function argument (line 8\ldots{}13).
``LaTeX::PGF::Diagram2D->new'' creates a new diagram, the grid size
is \(10\times{}6\)\,cm (line 16).
The image is used in a \LaTeX{} source written for a font size of
12\.pt (line 18).
The lower \(x\) axis (b: bottom) covers a range 0,0\ldots{}10,0
using a linear scale. Grid lines are drawn for a distance of 1 (line 20),
grid values are printed for a distance of 1 (line 21).
The left \(y\) axis (l: left) covers a range 0,0\ldots{}0,3.
We draw grid lines for a distance of 0,05 and create grid values
for a distance of 0,1 (lines 22 and 23).
The \textit{axis()\/} method of the diagram object returns a reference
for an axis object. A number of axis object methods is used to
set up the axis. Each of the methods returns the axis object reference,
so the methods can be cascaded.
The \textit{plot()\/} method of the diagram object creates a new
plot object and returns the reference to it (line 23).
The \textit{set\textunderscore{}xy\textunderscore{}fct()\/} method
configures the plot object to use the \textit{I()\/} to calculate
the values (line 26).
We save the diagram to file ``../examples/test001a.pgf'' (line 28).
\includepgfimage{../examples/test001a}{Current depending on resistor value.}
\clearpage
\subsection[Labels]{Example 2: Labels and units}
\lstinputlisting[float,language=Perl,title={../examples/test002a.pl}]{../examples/test002a.pl}
\includepgfimage{../examples/test002a}{Diagram with labels and units.}
The \textit{set\textunderscore{}label()\/} axis method sets the
axis label.
The \textit{set\textunderscore{}unit()\/} method sets the unit.
The label is normally set in math mode, the unit is written upright.
Both label and unit are passed to \LaTeX{} so we can use \LaTeX{}
markup here. For each backslash we want to pass to \LaTeX{} we have
( run in 1.150 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )