# pgfplots: multiple legends or one legend and a heading

In my plot, I want my standard legend that says what value of c corresponds to what color. However, I would also look to put the function in plot.

\documentclass[tikz]{standalone}
\usepackage{mathtools}
\DeclareMathOperator{\sech}{sech}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 1000,
domain = -10:10,
ymin = 0,
ymax = 2,
xmin = -7,
xmax = 7
]
\foreach \c/\col in {1/red, 2/blue, 3/green, 4/yellow}{
{2 * \c / (exp(.5 * sqrt(\c) * x) + exp(-.5 * sqrt(\c) * x))^2};
}
\temp
}
\legend{$c = 1$\\ $c = 2$\\ $c = 3$\\ $c = 4$\\}
\end{axis}
\end{tikzpicture}
\end{document}


I also want to put somewhere in the plot $$u(\xi = x - ct) = \frac{c}{2}\sech^2\left[\frac{\sqrt{c}}{2}(\xi - \xi_0)\right]$$.

How can this be achieved?

-
Don't know about the main question, but for the last one you can add a node inside the axis using the rel axis cs coordinate system: \node [right] at (rel axis cs:0,0.9) {$$u(\xi = x - ct) = \frac{c}{2}\sech^2\left[\frac{\sqrt{c}}{2}(\xi - \xi_0)\right]$$}; – Torbjørn T. Sep 12 '13 at 18:26

I'm not sure if I understand you correctly. But if you want a heading within your legend it might be best to draw the legend yourself. Simply add \labels after each \addplot command and use \ref{<label>} to get the respective legend image for use in your hand made legend.

\documentclass[tikz]{standalone}
\usepackage{mathtools}
\DeclareMathOperator{\sech}{sech}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 1000,
domain = -10:10,
ymin = 0,
ymax = 2,
xmin = -7,
xmax = 7
]
\foreach \c/\col in {1/red, 2/blue, 3/green, 4/yellow}{
\edef\temp{
{2 * \c / (exp(.5 * sqrt(\c) * x) + exp(-.5 * sqrt(\c) * x))^2};
\noexpand\label{p\c}  % labels for later referencing
}
\temp
}
\node [draw,fill=white,anchor=north east] at (rel axis cs: 0.99,0.99) {\shortstack[l]{
\ref{p1} $c=1$ \\
\ref{p2} $c=2$ \\
\ref{p3} $c=3$ \\
\ref{p4} $c=4$}};
\end{axis}
\end{tikzpicture}
\end{document}


-