在 `pgfplot` 中注释曲线系列

在 `pgfplot` 中注释曲线系列

我正在使用pgfplot来生成一系列曲线。我想用foreach变量指定的适当参数注释每条曲线(在本例中为)。但是当我在行中指定标签temperatureRatio时出现错误。我该如何解决这个问题?Undefined control sequencetemperatureRatio... node[right, pos=1, font=\small]{\temperatureRatio};

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

答案1

pgfplots具有不同特性的不同foreach宏。这里你必须使用\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}

在此处输入图片描述

相关内容