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.

I am using pgfplot to generate a family of curves. I would like to annotate each curve with the appropriate parameter as specified by foreach variable (in this case temperatureRatio). However I get an error when Undefined control sequence when I specify the label to temperatureRatio in the line ... node[right, pos=1, font=\small]{\temperatureRatio};. How can I fix this?

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
    \pgfplotsset{width=8cm,compat=newest}

\begin{document}

\noindent
\begin{minipage}{\linewidth}
    \centering
    \begin{tikzpicture}[scale=1]
    \begin{axis}[ xmin=0, xmax=1,   ymin=0, ymax=5,
                  xlabel={$\eta$},   ylabel={$\mathbb{P} = \dot{W} /(\dot{m} C_p T_1)$}
                ]
        \foreach \temperatureRatio in {4,...,10}
        {
            \addplot[domain=10:50, samples = 41, samples y = 0, blue]
            ({ 1 - x^(-0.2857) }, { (1 - x^(-0.2857))*(\temperatureRatio - x^(0.2857))})
            node[right, pos=1, font=\small]{\temperatureRatio};
        }

        \addplot[domain = 3:10, samples = 20, samples y = 0, red]
        ({1 - x^(-1/2)},{(sqrt(x)-1)^2})
        node[left,pos=0]{$\mathbb{P}_{\text{max}}$};

    \end{axis}
    \end{tikzpicture}
\end{minipage}

\end{document}
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

pgfplots has different foreach macros with different characteristics. Here you have to use \pgfplotsinvokeforeach.

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
    \pgfplotsset{width=8cm,compat=newest}

\begin{document}

\noindent
\begin{minipage}{\linewidth}
    \centering
    \begin{tikzpicture}[scale=1]
    \begin{axis}[ xmin=0, xmax=1,   ymin=0, ymax=5,
                  xlabel={$\eta$},   ylabel={$\mathbb{P} = \dot{W} /(\dot{m} C_p T_1)$}
                ]
        \pgfplotsinvokeforeach{4,...,10}
        {
            \addplot[domain=10:50, samples = 41, samples y = 0, blue]
            ({ 1 - x^(-0.2857) }, { (1 - x^(-0.2857))*(#1 - x^(0.2857))})
            node[right, pos=1, font=\small]{#1};
        }

        \addplot[domain = 3:10, samples = 20, samples y = 0, red]
        ({1 - x^(-1/2)},{(sqrt(x)-1)^2})
        node[left,pos=0]{$\mathbb{P}_{\text{max}}$};

    \end{axis}
    \end{tikzpicture}
\end{minipage}

\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.