Pgfplots 循环列表结果无颜色

Pgfplots 循环列表结果无颜色

我尝试使用 来cycle list name = MyCyclelist为我的图表提供相同的颜色/样式方案。但是所有线条都显示为黑色。我希望有人能帮忙。非常感谢!

我在标题中定义了循环列表,如下所示:

\pgfplotscreateplotcyclelist{MyCyclelist}{%
{darkgray, mark = none, thick},
{Green, mark = none, thick},
{MidnightBlue, mark = none, thick},
{Mahogany, mark = none, thick},
{RedOrange, mark = none, thick},
{RoyalPurple, mark = none, thick},
}

我的 pgfplot 文件非常标准:

\tikzsetnextfilename{nextfilename1}
\begin{tikzpicture}

\begin{axis}[
axis on top,
xlabel = abc,
ylabel = def,
xmin=0,
xmax=194,
ymin = 0,
legend style = {nodes=left, font =\footnotesize},
legend pos = north east,
height=0.5\textwidth,
width=\textwidth,
cycle list name=MyCyclelist
]
\pgfplotstableread{pictures/data.txt} \datatable
\addplot[legend image post style={sharp plot, line width=1pt, mark=none}, thick] table[x index = 0 , y index = 1 ] from \datatable;
\addlegendentry{abc}
\addplot[legend image post style={sharp plot, line width=1pt, mark=none}, thick] table[x index = 0 , y index = 3 ] from \datatable;
\addlegendentry{def}
    \end{axis}


\end{tikzpicture}

data.txt 如下所示:

0   6.21E-11    5.40E-11    8.73E-11
1   6.04E-11    4.86E-11    8.49E-11
2   5.16E-11    5.54E-11    7.30E-11
3   6.46E-11    4.63E-11    8.12E-11

答案1

如果命令没有可选参数,则\addplot使用循环列表。这可能是默认循环列表或自己的列表。

如果有可选参数,\addplot[<options>]则会忽略循环列表的设置。

如果要同时使用循环列表和可选参数,则必须+在命令和可选参数之间插入:\addplot+[<options>]。在这种情况下,首先设置循环列表的选项,然后附加可选参数内的选项。

\begin{filecontents*}{data.txt}
0   6.21E-11    5.40E-11    8.73E-11
1   6.04E-11    4.86E-11    8.49E-11
2   5.16E-11    5.54E-11    7.30E-11
3   6.46E-11    4.63E-11    8.12E-11
\end{filecontents*}

\documentclass[dvipsnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfplotscreateplotcyclelist{MyCyclelist}{%
  {darkgray, mark = none, thick},
  {Green, mark = none, thick},
  {MidnightBlue, mark = none, thick},
  {Mahogany, mark = none, thick},
  {RedOrange, mark = none, thick},
  {RoyalPurple, mark = none, thick},
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    axis on top,
    xlabel = abc,
    ylabel = def,
    xmin=0,
    xmax=4,%xmax=194,
    ymin = 0,
    legend style = {nodes=left, font =\footnotesize},
    legend pos = north east,
    height=0.5\textwidth,
    width=\textwidth,
    cycle list name=MyCyclelist
  ]
  \pgfplotstableread{data.txt} \datatable
  \addplot+[legend image post style={line width=1pt}] table[x index = 0 , y index = 1 ] from \datatable;
  \addlegendentry{abc}
  \addplot+[legend image post style={line width=1pt}] table[x index = 0 , y index = 3 ] from \datatable;
  \addlegendentry{def}
  \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述


注意:如果所有图例图像都应具有相同的线宽,则可以将其设置legend image post style={line width=1pt}为轴环境的一个选项。然后,您可以简单地使用\addplot table ...

相关内容