两个函数共同作用创建等距标记图时出现的问题

两个函数共同作用创建等距标记图时出现的问题

我在用着:

\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

    \makeatletter
    \tikzset{
      nomorepostactions/.code={\let\tikz@postactions=\pgfutil@empty},
      mymark/.style 2 args={decoration={markings,
        mark= between positions 0 and 1 step (1/11)*\pgfdecoratedpathlength with{%
            \tikzset{#2,every mark}\tikz@options
            \pgfuseplotmark{#1}%
          },  
        },
        postaction={decorate},
        /pgfplots/legend image post style={
            mark=#1,mark options={#2},every path/.append style={nomorepostactions}
        },
      },
    }
    \makeatother

    \pgfplotscreateplotcyclelist{my black white}{%
    solid, every mark/.append style={solid, fill=gray}, mymark=*\\%
    dotted, every mark/.append style={solid, fill=gray},mymark=square*\\%
    densely dotted, every mark/.append style={solid, fill=gray}, mymark=otimes*\\%
    loosely dotted, every mark/.append style={solid, fill=gray}, mymark=triangle*\\%
    dashed, every mark/.append style={solid, fill=gray},mark=diamond*\\%
    loosely dashed, every mark/.append style={solid, fill=gray},mark=*\\%
    densely dashed, every mark/.append style={solid, fill=gray},mymark=square*\\%
    dashdotted, every mark/.append style={solid, fill=gray},mark=otimes*\\%
    dasdotdotted, every mark/.append style={solid},mymark=star\\%
    densely dashdotted,every mark/.append style={solid, fill=gray},mark=diamond*\\%
    }

\begin{tikzpicture}[scale=1.25]

\begin{axis}[%
width=4.432in,
height=3.031in,
at={(0.743in,0.409in)},
scale only axis,
xmode=log,
legend style={legend cell align=left,align=left,draw=white!15!black},
xmin=0,
grid style = {dashed, black!15!white},
minor grid style = {dashed, black!15!white},
major grid style = {dashed, black!15!white},
cycle list name=my black white,
xlabel = {$x$},
ylabel = {$f(x)$},
xmax=10000,
xminorticks=true,
ymin=0,
grid=both,
ymax=10,
axis background/.style={fill=white}
]
\addplot% [color=mycolor1]
  table[row sep=crcr]{%
0    0\\
1    2\\
2    4\\
3    6\\
10    5\\
100    4\\
1000    1\\
500    4\\
};
\addlegendentry{Failing};

循环显示绘图线/标记样式,同时确保所有标记沿绘图路径彼此之间的距离相等。对于单个绘图,此方法可行,但当我尝试对多个绘图执行此操作时,会失败。有人能帮我修复它吗?使用 xlog 时,获得等距标记非常重要,否则它们会聚集到更高的值(除非您已按点进行对数扫描,但某些仪器并不总是提供此功能)。

我收到以下错误:

! Package pgfkeys Error: I do not know the key '/tikz/quare*' and I am going to
 ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3641 \end{axis}

标记类型的第一个字母被截断的地方:(Package pgfkeys Error: I do not know the key '/tikz/quare*' and I a...s)。


因此,根据以下建议,该my black white功能将变为:

\pgfplotscreateplotcyclelist{my black white}{%
mymark={*}{solid, fill=gray}\\%
mymark={square*}{solid, fill=gray}\\%
mymark={otimes*}{solid, fill=gray}\\%
%loosely dotted, every mark/.append style={solid, fill=gray}, mymark=triangle*\\%
%dashed, every mark/.append style={solid, fill=gray},mark=diamond*\\%
%loosely dashed, every mark/.append style={solid, fill=gray},mark=*\\%
%densely dashed, every mark/.append style={solid, fill=gray},mymark=square*\\%
%dashdotted, every mark/.append style={solid, fill=gray},mark=otimes*\\%
%dasdotdotted, every mark/.append style={solid},mymark=star\\%
%densely dashdotted,every mark/.append style={solid, fill=gray},mark=diamond*\\%
}

答案1

当样式定义如下时

mymark/.style 2 args={...}

这意味着该样式需要两个强制参数,并且应该用作

mymark={argument 1}{argument 2}.

在您使用 时mymark,您已经写了例如mymark=square*,因此看起来发生的事情是,TikZ 将其s作为第一个参数,并且由于某种原因quare*将其作为第二个参数。我不知道为什么它不会在第一行失败。

在 的定义中mymark,就像在宏的定义中一样,#1表示第一个参数,#2第二个参数。因此,如果您查看代码,就会发现这#1应该是一个标记类型,以及#2该标记的选项(例如颜色和大小)。这应该从

mark=#1,mark options={#2}

现在,您可以将第二个参数留空,但它必须存在,因此如果您不需要微调标记的外观,您可以更改

mymark=square*

mymark={square*}{solid,fill=gray}

对 的所有其他实例也同样如此。然后从循环列表中的每个样式中mymark删除。every mark/.append style={solid, fill=gray}

完整示例:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

    \makeatletter
    \tikzset{
      nomorepostactions/.code={\let\tikz@postactions=\pgfutil@empty},
      mymark/.style 2 args={decoration={markings,
        mark= between positions 0 and 1 step (1/11)*\pgfdecoratedpathlength with{%
            \tikzset{#2,every mark}\tikz@options
            \pgfuseplotmark{#1}%
          },  
        },
        postaction={decorate},
        /pgfplots/legend image post style={
            mark=#1,mark options={#2},every path/.append style={nomorepostactions}
        },
      },
    }
    \makeatother

    \pgfplotscreateplotcyclelist{my black white}{%
    solid, mymark={*}{solid, fill=gray}\\%
    dotted, mymark={square*}{solid, fill=gray}\\%
    densely dotted, mymark={otimes*}{solid, fill=gray}\\%
    loosely dotted, mymark={triangle*}{solid, fill=gray}\\%
    dashed, mymark={diamond*}{solid, fill=gray}\\%
    loosely dashed, mymark={*}{solid, fill=gray}\\%
    densely dashed, mymark={square*}{solid, fill=gray}\\%
    dashdotted,mymark={otimes*}{solid, fill=gray}\\%
    dasdotdotted, mymark={star}{solid, }\\%
    densely dashdotted,mark={diamond*}{solid, fill=gray}\\%
    }

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=4.432in,
height=3.031in,
at={(0.743in,0.409in)},
scale only axis,
xmode=log,
legend style={legend cell align=left,align=left,draw=white!15!black},
xmin=0,
grid style = {dashed, black!15!white},
minor grid style = {dashed, black!15!white},
major grid style = {dashed, black!15!white},
cycle list name=my black white,
xlabel = {$x$},
ylabel = {$f(x)$},
xmax=10000,
xminorticks=true,
ymin=0,
grid=both,
ymax=10,
axis background/.style={fill=white}
]
\addplot% [color=mycolor1]
  table[row sep=crcr]{%
0    0\\
1    2\\
2    4\\
3    6\\
10    5\\
100    4\\
1000    1\\
5000    4\\
};
\addplot% [color=mycolor1]
  table[row sep=crcr]{%
0    1\\
1    3\\
2    4\\
3    6\\
10    6\\
100    5\\
1000    2\\
5000    5\\
};
\addplot% [color=mycolor1]
  table[row sep=crcr]{%
0    2\\
1    4\\
2    6\\
3    8\\
10    7\\
100    5\\
1000    3\\
5000    6\\
};
\addlegendentry{Failing};
\addlegendentry{Failing2};
\addlegendentry{Failing3};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容