Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}{
      \edef\temp{\noexpand\addplot[red, \col]
        {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?

enter image description here

share|improve this question
2  
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
add comment

1 Answer 1

up vote 1 down vote accepted

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{
        \noexpand\addplot[red, \col]
        {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]{
        {\underline{Some Heading}} \\
        \ref{p1} $c=1$ \\
        \ref{p2} $c=2$ \\
        \ref{p3} $c=3$ \\
        \ref{p4} $c=4$}};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.