我怎样才能使用带有标记的 pgfplots 沿着路径绘制文字?

我怎样才能使用带有标记的 pgfplots 沿着路径绘制文字?

我正在使用decorations.text库来沿着绘制的路径设置文本pgfplots。装饰效果很好,没有痕迹,正如建议的那样这个答案,但路径上有标记,编译会失败Package pgf Error: I cannot decorate an empty path \end{axis}。为什么?有解决方法吗?

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

答案1

您可以通过禁用标记的装饰来修复此问题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}

相关内容