8

I am starting with the "pgfplots" package to make "tikzpicture". I have two problems. I would like to add a label (A) to the top left corner of tikz plot, like this figure :

enter image description here

I tried this :

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

And It doesn't do what I want!

This is my assumption :

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

My second problem is that I get curves with arrows:

enter image description here

Is there any way to remove them, in order to have a simple curve without arrows or marks?

1
  • 1
    You have explicitly added the arrow tips with the -> option that's used on all the \addplots. Apr 27, 2021 at 10:11

2 Answers 2

5

The issue with the arrows is easily solved: You add them yourself with ->, just remove this and the arrow heads disappear.

The second issue is slightly(!) more complicated: You need to set clip=false and you can then position a label using the rel axis cs:, i.e. the relative axis coordinate system (from 0 at your xmin and ymin to 1 at your xmax and ymax. However, you can give this node coordinates outside the range from 0 to 1, which will them appear outside the graph area.

Here is an example of how you might achieve this:

\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
  • 5
    I'd suggest clip mode=individual instead of clip=false. The difference is that then plots will still be clipped if they extend beyond the axis (e.g. if the domain extended to 7), but the node is not clipped. (Another strategy might be to add name=foo to the axis options, and \node at (foo.outer north west) {A}; after \end{axis}.) Apr 27, 2021 at 10:23
  • 1
    I wasn't aware of the clip mode option. This, indeed, sounds more like the desired effect.
    – Markus G.
    Apr 27, 2021 at 10:49
5

If you name the axis, then you can access the axis anchors outside the axis environment (no clipping).

I also moved the legend, although it's not clear exactly where you wanted it.

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

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .