在 tikz 图的左上角添加标签?

在 tikz 图的左上角添加标签?

我开始使用“pgfplots”包来制作“tikzpicture”。我有两个问题。我想在 tikz 图的左上角添加一个标签 (A),如下图所示:

在此处输入图片描述

我尝试了这个:

\node[above right, inner sep=0pt] at (fit.north west) {above right};
\node[left] at (-0.2, 1.5) {(A)};

但它并没有实现我想要的效果!

这是我的假设:

\begin{tikzpicture}

  \begin{axis}[ 
    legend style={at={((2.2, 0.75)},anchor=north east, at={(axis description cs:2.2, 0.75)}},
    xlabel={X TITLE},
    ylabel={Y TITLE},
    title={GRAPH TITLE},
    align =center,
    xmin=0,xmax=5,
    ymin=0,ymax=1.01,
    xtick pos=bottom,
    ytick pos=left
  ] 
%   \node[below left] at (axis description cs:1,1) {A};
    \addplot+[no markers, dotted, line width=2pt,color=red,%
         domain=0.01:4.9, samples=9,
         ->] {exp(-(1/1.5)*x)};
    \addlegendentry{REF 1}
    \addplot+[no markers,  thick,line width=2pt,color=red,%
         domain=0.01:4.9, samples=9, mark=none,
         ->] {exp(-(1/2)*x)};
    \addlegendentry{REF 2}
    \addplot+[no markers, dashed, line width=2pt,color=blue,%
         domain=0.01:4.9, samples=9,
         ->] {exp(-(1/3.5)*x)};
    \addlegendentry{REF 3}
    \addplot+[no markers, thick, line width=2pt,color=blue,%
         domain=0.01:4.9, samples=9, mark=none,
         ->] {exp(-(1/4)*x)};
    \addlegendentry{REF 4}
    
    \node[above right, inner sep=0pt] at (fit.north west) {above right};
    \node[left] at (-0.2, 1.5) {(A)};
    
  \end{axis}
\end{tikzpicture}

我的第二个问题是我得到带箭头的曲线:

在此处输入图片描述

有什么方法可以去除它们,以便得到一条没有箭头或标记的简单曲线?

答案1

箭头的问题很容易解决:您可以使用 自己添加它们->,只需删除它,箭头就会消失。

第二个问题稍微复杂一些:您需要设置clip=false,然后使用 定位标签rel axis cs:,即相对轴坐标系(从和处的 0到xmin和处ymin的 1 )。但是,您可以为该节点指定 0 到 1 范围之外的坐标,这些坐标将出现在图形区域之外。xmaxymax

以下是实现此目的的一个示例:

\documentclass{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
    
\begin{tikzpicture}
    
    \begin{axis}[ 
        legend style={at={((2.2, 0.75)},anchor=west, at={(rel axis cs:1.1, 0.5)}},
        xlabel={X TITLE},
        ylabel={Y TITLE},
        title={GRAPH TITLE},
        xmin=0,xmax=5,
        ymin=0,ymax=1.01,
        xtick pos=bottom,
        ytick pos=left,
        legend entries= {Ref 1, Ref 2, Ref 3, Ref 4},
        clip=false
        ] 
        \node[anchor=south east,font=\bfseries\Large\sffamily] at (rel axis cs:-0.1,1) {A};
        \addplot+[no markers, dotted, line width=2pt,color=red,%
        domain=0.01:4.9, samples=9] {exp(-(1/1.5)*x)};
        \addplot+[no markers,  thick,line width=2pt,color=red,domain=0.01:4.9, samples=9, mark=none] {exp(-(1/2)*x)};
        \addplot+[no markers, dashed, line width=2pt,color=blue,%
        domain=0.01:4.9, samples=9] {exp(-(1/3.5)*x)};
        \addplot+[no markers, thick, line width=2pt,color=blue,%
        domain=0.01:4.9, samples=9, mark=none] {exp(-(1/4)*x)};     
    \end{axis}
\end{tikzpicture}
\end{document}

答案2

如果您命名轴,那么您可以访问轴环境之外的轴锚点(无剪辑)。

我还移动了图例,尽管不清楚你想要它到底在哪里。

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

  \begin{axis}[ 
    legend style={at={(rel axis cs: 1.2, 0.75)},anchor=north west},
    xlabel={X TITLE},
    ylabel={Y TITLE},
    title={GRAPH TITLE},
    align =center,
    xmin=0,xmax=5,
    ymin=0,ymax=1.01,
    xtick pos=bottom,
    ytick pos=left,
    name=border
  ] 
%   \node[below left] at (axis description cs:1,1) {A};
    \addplot+[no markers, dotted, line width=2pt,color=red,%
         domain=0.01:4.9, samples=9,
         ] {exp(-(1/1.5)*x)};
    \addlegendentry{REF 1}
    \addplot+[no markers,  thick,line width=2pt,color=red,%
         domain=0.01:4.9, samples=9, mark=none,
         ] {exp(-(1/2)*x)};
    \addlegendentry{REF 2}
    \addplot+[no markers, dashed, line width=2pt,color=blue,%
         domain=0.01:4.9, samples=9,
         ] {exp(-(1/3.5)*x)};
    \addlegendentry{REF 3}
    \addplot+[no markers, thick, line width=2pt,color=blue,%
         domain=0.01:4.9, samples=9, mark=none,
         ] {exp(-(1/4)*x)};
    \addlegendentry{REF 4}

  \end{axis}

  \path (border.north west) ++(-0.2, 3pt) node[above left]{(A)};
\end{tikzpicture}
\end{document}

演示

相关内容