1

I'm trying to plot several results with \addplot table, for the color and style of the lines I created a "colorlist" with \pgfplotscreateplotcyclelist.

I also scattered my results to use different markers and include them in my title additionally. scatter and \pgfuseplotmark were used. For further information go here: include plotmarks in the title of a plot

Everything works fine except the legend. The colors defined in \pgfplotscreateplotcyclelist{mycolorlist} are not executed anymore. So, it looks like this:

enter image description here

Only the first line of the colorlist still influences the legend. So this line is the example of what i should look like.

My question is just about the markers in the legend, the ones on the line of the plot itself are red. And they should stay red.

The Code:

\begin{filecontents*}{data.txt}
a b d c
9 1 a 2   
8 2 b 4   
7 3 c 6   
6 4 d 8   
5 5 e 10  
4 6 f 12  
3 7 g 14  
2 8 x 16  
1 9 x 18  
\end{filecontents*}
\documentclass[paper=a4,ngerman,xcolor=dvipsnames]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{siunitx}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{lipsum}

\pgfplotscreateplotcyclelist{mycolorlist}{
blue!99!black,dashed,every mark/.append style={fill=blue!10!black},mark=+\\
red!99!black,solid,every mark/.append style={fill=blue!10!black},mark=+\\
green!99!black,densely dashed,every mark/.append style={fill=blue!10!black},mark=+\\
yellow!80!black,every mark/.append style={fill=blue!10!black},mark=+\\
}

\def\showmark#1{\tikz\node[red!95!black]{\pgfuseplotmark{#1}};}

\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
        grid=both,
        width=12cm, 
        height=9cm,
        axis equal,
        xtick pos=left,
        ytick pos=left,
        title style={draw,fill=none,name=legend},
        title={%
            \showmark{pentagon*}=$\SI{100}{\kilo\Hz}$,
            \showmark{triangle*}=$\SI{10}{\kilo\Hz}$,
            \showmark{square*}=$\SI{1}{\kilo\Hz}$,
            \showmark{diamond*}=$\SI{100}{\Hz}$,
            \showmark{10-pointed star}=$\SI{10}{\Hz}$,
            \showmark{oplus}=$\SI{1}{\Hz}$,
            \showmark{o}=$\SI{20}{\mHz}$},
        xlabel={R}, ylabel={Z}, 
        legend style={at={(0.02,0.98)},anchor=north west,cells={anchor=west}},
        legend style={font=\footnotesize},
        cycle list name=mycolorlist,
        scatter,
        point meta=explicit symbolic,
        scatter/classes={
          x={},% empty argument means: use the default style       
          g={mark=pentagon*,red!95!black},
          f={mark=triangle*,red!95!black},
          e={mark=square*,red!95!black},
          d={mark=diamond*,red!95!black},
          c={mark=10-pointed star,red!95!black},
          b={mark=oplus,red!95!black},
          a={mark=o,red!95!black},
          z={mark=*,red!80!black}
          },
        ]
        \addplot table [x=b,y=c, meta=d]{data.txt};
        \addplot table [x=c,y=b, meta=d]{data.txt};
        \addplot table [x=a,y=c, meta=d]{data.txt};
        \addplot table [x=b,y=a, meta=d]{data.txt};

        \legend{1, 2, 3 ,4}
   \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}
Björn
  • 327
  • In section 4.5.12 on page 112 of the PGFPlots manual (v1.14) it is stated: "The generation of a legend works as for a normal plot - but scatter/classes requires one legend entry for every provided class. It communicates the class labels to the legend automatically. It works as if there had been different \addplot commands, one for every class label.". So I guess this is the intended behavior. ... – Stefan Pinnow Jan 13 '17 at 22:13
  • 1
    ... The only strange thing here is that the fill color and the line style of the first cycle list entry are also applied to all the other legend entries. But I think the scatter interface has never been designed for your use-case, so it is the question if this can be considered to be a bug. – Stefan Pinnow Jan 13 '17 at 22:15

0 Answers0