5

I am using the decorations.text library to set text along a path drawn by pgfplots. The decoration works fine without marks, as suggested in this answer, but with marks on the path, the compilation fails with Package pgf Error: I cannot decorate an empty path \end{axis}. Why, and is there a workaround?

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[
    no markers,
    decoration={
        text along path,
        text={This is my path},
    },
    postaction={decorate},
] coordinates {(0,0) (10,1)};
% \addplot+[
%     mark=*,
%     decoration={
%     text along path,
%     text={This is my path},
%     },
%     postaction={decorate},
% ] coordinates {(0,1) (10,0)}; %This one fails
\end{axis}
\end{tikzpicture}
\end{document}
darthbith
  • 7,384
  • 1
    By the way, for this simple example, the sloped option to a node after the addplot would be much simpler, but of course the real use case has a curved plot for which sloped isn't very helpful. – darthbith Dec 11 '14 at 21:35

1 Answers1

6

You can fix the problem by disabling the decoration for the marks using mark options={decoration={name=none}}:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{decorations.text}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[
    no markers,
    decoration={
        text along path,
        text={This is my path},
    },
    postaction={decorate},
] coordinates {(0,0) (10,1)};
 \addplot+[
     mark=*,
     decoration={
     text along path,
     text={This is my path},
     },
     mark options={decoration={name=none}},
     postaction={decorate},
 ] coordinates {(0,1) (10,0)}; %This one fails
\end{axis}
\end{tikzpicture}
\end{document}
Jake
  • 232,450