2

I have an axis environment in a tikzpicture with a straight line exceeding the axis. At the end of the line I add a node whose text partially also exceeds the axis and is clipped. Clipping the line is ok but the whole node text should be visible. I tried to use clip mode=individual from here but I didn't work. Then I also added clip=false to the node properties. But it didn't work neither. What is wrong in my code?

\documentclass[11pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}[]
\begin{axis}[clip mode=individual,
xmin=5, xmax=15, ymin=22, ymax=60,
]
\addplot[domain=4:14]{16.46/3.6*x} node [at end,anchor=south east,sloped] () {testtesttest};
\end{axis}
\end{tikzpicture}
\end{document}

Many thanks.

2

The problem is that clip mode=individual means that the paths added by addplot will be clipped, and the others no. So you can do something like this (defining functions can help to streamline it, but this is the idea): replicate the line with an (invisible) path and plot the label along it.

\documentclass[11pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}[]
\begin{axis}[clip mode=individual,
xmin=5, xmax=15, ymin=22, ymax=60,
]
\addplot[domain=4:14]{16.46/3.6*x}; 
\path (6, {16.46/3.6*6}) --  (14, {16.46/3.6*14}) node [at end,anchor=south east,sloped] () {testtesttest};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Nice! Maybe \addplot[domain=4:14]{16.46/3.6*x} coordinate[pos=0] (p0) coordinate[pos=1] (p1); \path (p0) -- (p1) node [at end,anchor=south east,sloped] () {testtesttest}; is less painful. – user121799 May 26 at 18:05
  • @marmot yes, that's a great idea. – Rmano May 26 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.