我可以将 pgfplots 中的节点锚定到哪些实体?

我可以将 pgfplots 中的节点锚定到哪些实体?

我觉得很难读懂pgfplots 手册,我可以参考哪些实体,例如,锚节点提供更多信息。

例如在下面的例子中,我可以引用哪些或所有实体?

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}

\begin{document}
 \begin{tikzpicture}
    \begin{axis}[
        title=hello,
        xlabel=x,   
     ]
        \addplot[domain=-1:1]   {(x-.2)^3 + 1};
     
        \addplot[domain=-1:1]   {x+1.5};    
    \end{axis}  
 \end{tikzpicture}
\end{document}

结果

答案1

简而言之,至少可以参考:

  • 实体,您可以通过以下方式命名name=
  • 预定义实体,例如current axiscurrent plot begincurrent plot end

请参阅下面的示例。笔记节点的顺序和位置可能是相关的,参见示例current plot ...笔记节点使用的各种样式选项。我建议在pgfplots-手册

% ~~~ 10.04.2024: Where can I name things like a node? ~~~~~~~~~

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}

\begin{document}
 \begin{tikzpicture}
    \begin{axis}[
        name=AX,                    % <<<
        title=hello,                % not here
        title style={name=TS},      % <<<
        xlabel=x,                   % not here
        xlabel style={name=XL},     % <<<
        ylabel=y,                   % not here
        ylabel style={name=YL},     % <<<
     ]
     \addplot[
        domain=-1:1,
        %name path=CRV, % needs fill between
        %name=AP,       % no
     ]{(x-.2)^3 + 1};
     
     \addplot[domain=-1:1,]{x+1.5};
    
    \end{axis}  
    
    % ~~~ current axis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[anchor=west,red,circle,draw]  at (current axis.east)  {CA}; 
    
    % ~~~ current plot ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[red,circle,draw]              at (current plot begin) {CPb}; 
    \node[red,circle,draw]              at (current plot end)   {CPe}; 
    
    % ~~~ named axis, see above ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[anchor=west,teal]     at (AX.south east)      {AX}; 
    \node[anchor=east,teal]     at (AX.north west)      {AX}; 
    \node[teal]                 at (AX.outer north west){AX}; 
    \node[teal]                 at (AX.origin)          {AXorg}; 
    \node[teal]                 at (AX.center)          {AXcnt}; 
    
    % ~~~ named styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[anchor=west,purple,draw]  at (TS.east)    {TS}; 
    \node[anchor=west,purple,draw]  at (XL.east)    {XL}; 
    \node[anchor=west,purple,draw]  at (YL.east)    {YL}; 
 \end{tikzpicture}
\end{document}

结果

相关内容