% main=manual.tex


\section{More examples}
This section contains a catalogue of different \PGFPlots\ features by example.
\label{sec:examples}%
\begingroup
\subsection{Legend position}
\begin{lstlisting}
\tikzstyle{every axis legend}+=
	[at={(0.03,0.03)},anchor=south west]%
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\addplot plot coordinates {
		(5,		8.312e-02)
		(17,	2.547e-02)
		(49,	7.407e-03)
		(129,	2.102e-03)
		(321,	5.874e-04)
		(769,	1.623e-04)
		(1793,	4.442e-05)
		(4097,	1.207e-05)
		(9217,	3.261e-06)
	};

	....

	\legend{$d=2$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}
\def\plots{%
	\addplot plot coordinates {
		(5,		8.312e-02)
		(17,	2.547e-02)
		(49,	7.407e-03)
		(129,	2.102e-03)
		(321,	5.874e-04)
		(769,	1.623e-04)
		(1793,	4.442e-05)
		(4097,	1.207e-05)
		(9217,	3.261e-06)
	};

	\addplot plot coordinates {
		(7,		8.472e-02)
		(31,	3.044e-02)
		(111,	1.022e-02)
		(351,	3.303e-03)
		(1023,	1.039e-03)
		(2815,	3.196e-04)
		(7423,	9.658e-05)
		(18943,	2.873e-05)
		(47103,	8.437e-06)
	};

	\addplot plot coordinates {
		(9,	7.881e-02)
		(49,	3.243e-02)
		(209,	1.232e-02)
		(769,	4.454e-03)
		(2561,	1.551e-03)
		(7937,	5.236e-04)
		(23297,	1.723e-04)
		(65537,	5.545e-05)
		(178177,	1.751e-05)
	};

	\addplot plot coordinates {
		(11,	6.887e-02)
		(71,	3.177e-02)
		(351,	1.341e-02)
		(1471,	5.334e-03)
		(5503,	2.027e-03)
		(18943,	7.415e-04)
		(61183,	2.628e-04)
		(187903,	9.063e-05)
		(553983,	3.053e-05)
	};

	\addplot plot coordinates {
		(13,	5.755e-02)
		(97,	2.925e-02)
		(545,	1.351e-02)
		(2561,	5.842e-03)
		(10625,	2.397e-03)
		(40193,	9.414e-04)
		(141569,	3.564e-04)
		(471041,	1.308e-04)
		(1496065,	4.670e-05)
	};
	\legend{$d=2$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
	%--------------------------------------------------
	% \addplot plot coordinates {
	% 	(1.60944,-2.48752)
	% 	(2.83321,-3.67031)
	% 	(3.89182,-4.90531)
	% 	(4.85981,-6.16490)
	% 	(5.77144,-7.43988)
	% 	(6.64509,-8.72625)
	% 	(7.49165,-10.02171)
	% 	(8.31801,-11.32467)
	% 	(9.12880,-12.63347)
	% };
	%-------------------------------------------------- 

	%--------------------------------------------------
	% \addplot plot coordinates {
	% 	(1.94591,-2.46843)
	% 	(3.43399,-3.49197)
	% 	(4.70953,-4.58327)
	% 	(5.86079,-5.71278)
	% 	(6.93049,-6.86963)
	% 	(7.94272,-8.04829)
	% 	(8.91234,-9.24515)
	% 	(9.84919,-10.45743)
	% 	(10.76009,-11.68282)
	% };
	%-------------------------------------------------- 

	%--------------------------------------------------
	% \addplot plot coordinates {
	% 	(2.19722,-2.54068)
	% 	(3.89182,-3.42861)
	% 	(5.34233,-4.39638)
	% 	(6.64509,-5.41393)
	% 	(7.84815,-6.46903)
	% 	(8.97929,-7.55482)
	% 	(10.05608,-8.66643)
	% 	(11.09037,-9.80004)
	% 	(12.09053,-10.95252)
	% };
	%-------------------------------------------------- 

	%--------------------------------------------------
	% \addplot plot coordinates {
	% 	(2.39790,-2.67548)
	% 	(4.26268,-3.44917)
	% 	(5.86079,-4.31187)
	% 	(7.29370,-5.23369)
	% 	(8.61305,-6.20135)
	% 	(9.84919,-7.20679)
	% 	(11.02162,-8.24414)
	% 	(12.14368,-9.30872)
	% 	(13.22489,-10.39672)
	% };
	%-------------------------------------------------- 

	%--------------------------------------------------
	% \addplot plot coordinates {
	% 	(2.56495,-2.85506)
	% 	(4.57471,-3.53179)
	% 	(6.30079,-4.30404)
	% 	(7.84815,-5.14269)
	% 	(9.27096,-6.03371)
	% 	(10.60145,-6.96818)
	% 	(11.86054,-7.93940)
	% 	(13.06270,-8.94206)
	% 	(14.21835,-9.97183)
	% };
	%-------------------------------------------------- 

	%--------------------------------------------------
	% \legend{$d=2$\\$d=3$\\$d=4$\\$d=5$\\$d=6$\\}
	%-------------------------------------------------- 
}%
{%
\legendpreset{font=\footnotesize}%
\tikzstyle{every axis legend}+=
	[at={(0.03,0.03)},anchor=south west]%
\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}
}

\subsection{Font size and line width}
\begin{lstlisting}
\tikzstyle{every axis legend}+=%
	[at={(0.03,0.03)},anchor=south west]%
\tikzstyle{every tick}+=[line width=0.6pt]%
\begin{tikzpicture}[font=\large,line width=1pt]
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\addplot ....
	...
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}

{%
\tikzstyle{every axis legend}+=
	[at={(0.03,0.03)},anchor=south west]%
\tikzstyle{every tick}+=[line width=0.6pt]
\begin{center}
\begin{tikzpicture}[font=\large,line width=1pt]
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}
}%

\subsection{Changing line specifications}
\subsubsection{Using another, predefined list}
{%
\begin{lstlisting}
\listcopy\blackwhiteplotspeclist\to\autoplotspeclist%
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	...
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}

\listcopy\blackwhiteplotspeclist\to\autoplotspeclist%
\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}

\subsubsection{Defining new lists}
\begin{lstlisting}
% will cycle through these three elements:
\listnew{\autoplotspeclist}{%
	red,dotted,mark=-,mark options={solid}\\%
	black,dashed,mark=pentagon,mark options={solid}\\%
	mark options={fill=blue!40},mark=diamond*,blue\\%
}%
\tikzstyle{every axis legend}+=%
	[at={(1.03,1)},anchor=north west]%
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	...
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}

\listnew{\autoplotspeclist}{%
	red,dotted,mark=-,mark options={solid}\\%
	black,dashed,mark=pentagon,mark options={solid}\\%
	mark options={fill=blue!40},mark=diamond*,blue\\%
}%
\tikzstyle{every axis legend}+=%
	[at={(1.03,1)},anchor=north west]%
\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}
}%

\subsection{Changing the ticks}
\subsubsection{Placing ticks at $10^i$}
\begin{lstlisting}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xtickten={0,2,3,4,6,...,10},% place tickmarks at 10^0, 10^2,...
		ytickten={-6,-4,...,2},
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	....
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}

\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xtickten={0,2,3,4,6,...,10},
		ytickten={-6,-4,...,2},
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}

\subsubsection{Placing ticks anywhere}
\begin{lstlisting}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xtick={12,9897,1468864}
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	....
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}

\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xtick={12,9897,1468864},%2.5,9.2,14.2},
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\end{loglogaxis}
\end{tikzpicture}
\end{center}

\subsection{Annotating plots}
\label{sec:annot:plot}%
\subsubsection{Example: Placing Data Cursors}
\begin{lstlisting}
\tikzstyle{annotation}=[fill=white,draw=black,font=\footnotesize]
\tikzstyle{annotedge}=[->,shorten >=3pt]
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]

	....

	\addplot plot coordinates {
		(13,	5.755e-02)
		(97,	2.925e-02)
		(545,	1.351e-02)
		(2561,	5.842e-03)
		(10625,	2.397e-03)
		(40193,	9.414e-04)
		(141569,	3.564e-04)
		(471041,	1.308e-04)
		(1496065,	4.670e-05)
	};
	...

	% remember this coordinate under the name 'bad'
	\axispath\node[coordinate] (bad) at 
		(8.61305,-6.20135) % = (log(10625), log(2.397e-03))
		{};
	\axispath\node[coordinate] (good) at 
		(12.14368,-9.30872)
		{};

	% place a node above 'bad' and draw an edge to 'bad':
	\axispath\node[annotation,above of=bad] 
		{Bad!} 
		edge[annotedge] (bad);
	\axispath\node[annotation,above right of=good]
		{Good!} 
		edge[annotedge] (good);
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}
\begin{center}
\begin{tikzpicture}[node distance=1cm]
\tikzstyle{annotation}=[fill=white,draw=black,font=\footnotesize]
\tikzstyle{annotedge}=[->,shorten >=3pt]
	\begin{loglogaxis}[
		xlabel={\textsc{Dof}},
		ylabel={$L_2$ Error}
	]
	\plots
	\axispath\node[coordinate] (bad) at 
		(8.61305,-6.20135) 
		{};
	\axispath\node[coordinate] (good) at 
		(12.14368,-9.30872)
		{};

	\axispath\node[annotation,above of=bad] 
		{Bad!} 
		edge[annotedge] (bad);
	\axispath\node[annotation,above right of=good]
		{Good!} 
		edge[annotedge] (good);
	\end{loglogaxis}
\end{tikzpicture}
\end{center}

One remark: the \lstinline!\axispath! prefix is necessary because neither axis nor plots will be drawn until the $x$- and $y$-limits have been determined. All drawing commands are postponed until \lstinline!\end{axis}! (unless you explicitly provide the options \lstinline!xmin!, \lstinline!xmax!, \lstinline!ymin! and \lstinline!ymax!).

\subsubsection{Example: Slopes of line segments}
\begin{lstlisting}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel=\textsc{Dof},
		ylabel=$L_2$ Error
	]
	\axispath\draw 
			(7.49165,-10.02171) 
		|-	(8.31801,-11.32467) 
		node[near start,left] {$\frac{dy}{dx} = -1.58$};

	\addplot ....
	...
	\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}
\begin{center}
\begin{tikzpicture}
	\begin{loglogaxis}[
		xlabel=\textsc{Dof},
		ylabel=$L_2$ Error
	]
	\axispath\draw 
			(7.49165,-10.02171) 
		|-	(8.31801,-11.32467) 
		node[near start,left] {$\frac{dy}{dx} = -1.58$};
	\plots
	
	\end{loglogaxis}
\end{tikzpicture}
\end{center}

\endgroup
