在 pgf 图中定位节点

在 pgf 图中定位节点

我想将显示函数规则的节点移动到图的右上角,最好也用方框标记。我应该怎么做?

可编译代码:

\documentclass{article}
\usepackage{pgfplots, tikz}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xlabel = $x$,
    ylabel = $P(x)$,
    xlabel style={anchor=north east, inner xsep=0pt},
    ylabel style={anchor=north east, inner ysep=0pt},
    grid, 
    minor tick num=4,
    grid style={very thin,dashed},
    xmin=-0.5,
    ymin=-150, ymax=250,
    enlarge y limits=0.1,  
    legend style = {font=\footnotesize}]
\addplot [
    domain=0:5.513743717,
    samples=200,
    color=blue,
    thick
    ]
    {95*x-153*x^0.83-38};
    
\addplot [
    domain=5.513743717:27,
    samples=200,
    color=red,
    thick
    ]
    {95*x-153*x^0.83-38};
    node[left=3mm, text=black] {$P(x)=95x-153x^{0.83}-38$}
\addplot[
    color=black,
    mark=*,
    ]
    coordinates {
    (5.513743717, -145.285)
    };
\end{axis}
    \end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

答案1

由于您完全重写了您的问题,因此有了新的答案:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.17}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xlabel = $x$,
    ylabel = $P(x)$,
    xlabel style={anchor=north east, inner xsep=0pt},
    ylabel style={anchor=north east, inner ysep=0pt},
    grid,
    minor tick num=4,
    grid style={very thin,dashed},
    xmin=-0.5,
%    ymin=-150, ymax=250,
    enlarge y limits=0.1,
    legend style = {font=\footnotesize}]
\addplot [
    domain=0:5.513743717,
    samples=200,
    color=blue,
    thick
    ]
    {95*x-153*x^0.83-38};

\addplot [
    domain=5.513743717:27,
    samples=200,
    color=red,
    thick
    ]
    {95*x-153*x^0.83-38} 
    node[at start, circle, inner sep=2pt,fill=black] {}
    node[left=3mm, text=black] {$P(x)=95x-153x^{0.83}-38$};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

像这样:

在此处输入图片描述

或者像这样:

在此处输入图片描述

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.17}

\begin{document}
    \begin{tikzpicture}[auto]
\begin{axis}[
    xlabel = $x$,
    ylabel = $f(x)$,
]
\addplot [
    samples=2,
    color=red, thick
    ]
    {x} node[near end, sloped, text=black] {$f(x)=x$}   % used at first image
%    {x} node[left=3mm, text=black] {$f(x)=x$}          % used at second image
    ;
\end{axis}
    \end{tikzpicture}
\end{document}

相关内容