<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\section{Graphing functions}
\label{sec:graphing}

Among the most common types of figures for \TeX{} users are those which
are the graphs of functions of a single variable.  Hobby recognized this
and constructed a package to accomplish this task.  It is invoked by

\begin{lstlisting}[style=MP]
input graph;
\end{lstlisting}

\MP{} has the ability to construct data (i.e., ordered pairs) for
graphing simple functions.  However, for more complicated functions, the
data should probably be constructed using external programs such as
\acro{MATLAB} (or Octave), Maple, Mathematica, Gnuplot, et. al.

A typical data file, say \File{data.d}, to be used with the \File{graph}
package may have contents

\vspace{8pt}
\noindent%
\begin{tabular}[b]{@{\hspace{48pt}}l@{}}
  \lstinputlisting[style=text, boxpos=b]{data.d}
\end{tabular}%
\qquad%
\attach[subject={Graph data}]{data.d}
\vspace{8pt}

This data represents the graph of $f(x)=\sqrt{x}$ for six equally spaced
points in $[0,1]$.  To graph this data, the size of the graph must first
be decided.  Choosing a width of $144\mathrm{\ bp}$ and a height of
$89\mathrm{\ bp}$, a minimally controlled plot (as in
\autoref{fig:data}) of this data can be generated by

\begin{lstlisting}[style=MP]
draw begingraph(144bp,89bp);
   gdraw "data.d";
endgraph;
\end{lstlisting}

The \File{graph} package provides many commands used to customize
generated graphs, and these commands are fully documented in the
manual~\cite{hobby:graph} for the \File{graph} package.

\begin{figure}
  \begin{withattachment}{data.mp}
    \centering
    \includegraphics{data.mps}
  \end{withattachment}
  \caption{$f(x)=\sqrt{x}$ using the \texttt{graph} package}
  \label{fig:data}
\end{figure}
</pre></body></html>