如果 \addplot+ 顺序发生变化,情节线的样式也会发生变化

如果 \addplot+ 顺序发生变化,情节线的样式也会发生变化

我对这个简单的图有一个奇怪的问题。我需要绘制四对图,每对图都由一条近似曲线(连续线)和一条实线(虚线)组成。出于某些原因,我无法理解图 (t,y_p20a) 是虚线,但它不应该是虚线。另一个奇怪的事情是,如果我以不同的顺序重新排列图对,例如 12 34 78 56,问题仍然出现在第七张图上(在本例中是数字 5)。有什么想法吗?

\documentclass{standalone}

\usepackage{filecontents}
\begin{filecontents*}{data.csv}
t,y_m20r,y_m10r,y_p10r,y_p20r,y_m20a,y_m10a,y_p10a,y_p20a
0,0,0,0,0,0,0,0,0
1,0.022341,0.0099981,-0.0082633,-0.015207,0.018097,0.0090484,-0.0090484,-0.018097
2,0.03993,0.017993,-0.015022,-0.027751,0.032749,0.016375,-0.016375,-0.032749
3,0.053529,0.024287,-0.020482,-0.037983,0.044449,0.022225,-0.022225,-0.044449
4,0.063789,0.02914,-0.024824,-0.046211,0.053626,0.026813,-0.026813,-0.053626
5,0.071269,0.032777,-0.028206,-0.05271,0.060653,0.030327,-0.030327,-0.060653
\end{filecontents*}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotstableread[col sep=comma,header=true]{data.csv}\data

\begin{document}\begin{tikzpicture}\begin{axis}

  \addplot table[x = t, y = y_m20a] from \data;
  \addplot [dashed] table[x = t, y = y_m20r] from \data;

  \addplot table[x = t, y = y_m10a] from \data;
  \addplot [dashed] table[x = t, y = y_m10r] from \data;

  \addplot table[x = t, y = y_p10a] from \data;
  \addplot [dashed] table[x = t, y = y_p10r] from \data;

  \addplot table[x = t, y = y_p20a] from \data; % THIS ONE SHOULD NOT BE DASHED
  \addplot [dashed] table[x = t, y = y_p20r] from \data;

\end{axis}\end{tikzpicture}\end{document}

答案1

这一切都由所谓的 决定cycle list。如果你改变它,你就会去掉破折号。这是一个例子。

\documentclass[tikz,border=3.14mm]{standalone}

\usepackage{filecontents}
\begin{filecontents*}{data.csv}
t,y_m20r,y_m10r,y_p10r,y_p20r,y_m20a,y_m10a,y_p10a,y_p20a
0,0,0,0,0,0,0,0,0
1,0.022341,0.0099981,-0.0082633,-0.015207,0.018097,0.0090484,-0.0090484,-0.018097
2,0.03993,0.017993,-0.015022,-0.027751,0.032749,0.016375,-0.016375,-0.032749
3,0.053529,0.024287,-0.020482,-0.037983,0.044449,0.022225,-0.022225,-0.044449
4,0.063789,0.02914,-0.024824,-0.046211,0.053626,0.026813,-0.026813,-0.053626
5,0.071269,0.032777,-0.028206,-0.05271,0.060653,0.030327,-0.030327,-0.060653
\end{filecontents*}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotstableread[col sep=comma,header=true]{data.csv}\data
\pgfplotsset{
    cycle list={
        {mark=*},
        {mark=*},
        {mark=diamond*},
        {mark=triangle*},  {blue,mark=triangle*},
        {red, mark=diamond*},   {blue,mark=diamond*},
        {red, mark=pentagon*},  {blue,mark=pentagon*}
    }}
\begin{document}
\begin{tikzpicture}
\begin{axis}

  \addplot table[x = t, y = y_m20a] from \data;
  \addplot [dashed] table[x = t, y = y_m20r] from \data;

  \addplot table[x = t, y = y_m10a] from \data;
  \addplot [dashed] table[x = t, y = y_m10r] from \data;

  \addplot table[x = t, y = y_p10a] from \data;
  \addplot [dashed] table[x = t, y = y_p10r] from \data;

  \addplot table[x = t, y = y_p20a] from \data; % THIS ONE SHOULD NOT BE DASHED
  \addplot [dashed] table[x = t, y = y_p20r] from \data;

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容