1

I have a weird issue with this simple plot. I need to draw four couples of plots, each made by an approximate curve (continuous line) and the real curve (dashed line). For some reasons I can't understand the plot (t,y_p20a) is dashed, but it shouldn't be. Another weird thing is that if I rearrange the plot couples in a different order, such as 12 34 78 56, the issue is still on the seventh plot (which is, in this case, the number 5). Any idea?

\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 Answer 1

2

This is all determined by the so-called cycle list. If you change it, you get rid of the dashes. Here is an example.

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

enter image description here

5
  • Thank you! Is there any way to just ignore any cycle list? In my document (here I wrote just a MWE with no formatting) I added the options no markers, thick to the axis environment and I specified a color for each \addplot+ command, so I don't need pgfplots to cycle within any formatting list, everything is manually specified for each plot. I tried to add the solid option to the axis environment, and I also tried with every axis plot/.style, with no success... Commented Dec 20, 2018 at 23:30
  • 1
    @Taekwondavide One quick way is to say \pgfplotsset{cycle list={}} and then set the marks, colors and line styles by hand, if needed. Or just make sure every plot has some options. The pgfplots manual says on p. 25 "Note furthermore that we omitted any options after \addplot. As explained in Section 3.2.1, this tells pgfplots to consult its cycle list to determine a suitable option list."
    – user121799
    Commented Dec 20, 2018 at 23:44
  • Thank you, now it works. However, is there any reason for which I can globally set no markers but I cannot set solid? The first overrides the cycle list, the second is just ignored... Commented Dec 20, 2018 at 23:55
  • 1
    I just tried this (as a tikzpicture option), it doesn't work. I think it's just for marks and not for the line, as I replaced solid with yellow and it changed the border color of marks. Commented Dec 21, 2018 at 0:05
  • 1
    @Taekwondavide Yes, you're right. I have no idea why it is seemingly impossible to override these things globally in the same way as other things. Nevertheless the things mentioned above seem to work.
    – user121799
    Commented Dec 21, 2018 at 0:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .