颜色列表不起作用

颜色列表不起作用

当我尝试addplot使用颜色时cycle list name=color list,由于某种原因,它不起作用,所有线条的颜色都保持黑色。这是我的代码:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\pgfplotsset{scaled y ticks=false}
\begin{tikzpicture}
\begin{axis}
[xlabel={Dan},ylabel={Promjena vrijednosti (\%)},
yticklabel=\pgfmathparse{100*\tick}\pgfmathprintnumber{\pgfmathresult}\,\%,
ylabel style={align=center,text width=5cm},
xticklabel style={font=\small,/pgf/number format/fixed, /pgf/number format/precision=2},
yticklabel style={font=\small},
cycle list name=color list]
\addplot[line width=0.2mm] table[x=D,y=R]{C:/Users/User/Desktop/maturski/podaciAnalize/brownianMotion/0.dat};
\addplot[line width=0.2mm] table[x=D,y=R]{C:/Users/User/Desktop/maturski/podaciAnalize/brownianMotion/1.dat};
\addplot[line width=0.2mm] table[x=D,y=R]{C:/Users/User/Desktop/maturski/podaciAnalize/brownianMotion/2.dat};
\addplot[line width=0.2mm] table[x=D,y=R]{C:/Users/User/Desktop/maturski/podaciAnalize/brownianMotion/3.dat};
\addplot[line width=0.2mm] table[x=D,y=R]{C:/Users/User/Desktop/maturski/podaciAnalize/brownianMotion/4.dat};
\end{axis}
\end{tikzpicture}

\end{document}

以下是示例文件0.dat

R   D
0   0
0.00365519  1
-0.0167845  2
0.010772    3
0.00556351  4
0.0112872   5
-0.00457628 6
0.00495608  7
0.0135412   8
0.00103665  9
0.00274946  10
-0.00198433 11
0.0170662   12
-0.00503909 13
0.0172626   14
-0.00211349 15
0.00543873  16
0.00678182  17
-0.00100652 18
0.000851647 19
-0.00184836 20
-0.00664038 21
0.00061449  22

答案1

为了cycle list name工作,您必须使用\addplot+而不是\addplot

摘自pgfplots手册(修订版 1.18.1,第 4.7.7 章):

/pgfplots/cycle list name={name}
允许指定一个绘图规范列表,该列表将用于每个没有明确绘图规范的命令。因此,如果您写入或不使用方括号(如),\addplot则将使用当前活动的循环列表 。\addplot+[keys] ...;\addplot[explicit plot specification] ...;

例如:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{filecontents}{0.dat}
R   D
0   0
0.00365519  1
-0.0167845  2
0.010772    3
0.00556351  4
0.0112872   5
-0.00457628 6
0.00495608  7
0.0135412   8
0.00103665  9
0.00274946  10
-0.00198433 11
0.0170662   12
-0.00503909 13
0.0172626   14
-0.00211349 15
0.00543873  16
0.00678182  17
-0.00100652 18
0.000851647 19
-0.00184836 20
-0.00664038 21
0.00061449  22
\end{filecontents}

\begin{document}

\pgfplotsset{scaled y ticks=false}
\begin{tikzpicture}
\begin{axis}
[xlabel={Dan},ylabel={Promjena vrijednosti (\%)},
yticklabel=\pgfmathparse{100*\tick}\pgfmathprintnumber{\pgfmathresult}\,\%,
ylabel style={align=center,text width=5cm},
xticklabel style={font=\small,/pgf/number format/fixed, /pgf/number format/precision=2},
yticklabel style={font=\small},
cycle list name=color list]
\addplot+[line width=0.2mm] table[x=D,y=R]{0.dat};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容