0

I want to plot one section of data and create a graph with markers. Some "random" markers (so not like every 5th for example) should have different colors for better differentiation from the rest.

How can I set a "red X" for the third measurement point (3/6) and a black circle for (8/16)?

enter image description here

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


\pgfplotscreateplotcyclelist{mycolorlist}{
blue!50!green,every mark/.append style={fill=blue!10!black},mark=x\\
}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
        grid=both,
        width=12cm, 
        height=9cm,
        xtick pos=left,
        ytick pos=left,
        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,
        ]
        \addplot table [x=b,y=c]{data.txt};

        \legend{Z}
   \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}
2

2 Answers 2

4

If you don't find a better solution, you can always repeat the plot for the desired different coordinates:

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


\pgfplotscreateplotcyclelist{mycolorlist}{
blue!50!green,every mark/.append style={fill=blue!10!black},mark=x\\
}

\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
        grid=both,
        width=12cm, 
        height=9cm,
        xtick pos=left,
        ytick pos=left,
        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,
        ]
        \addplot table [x=b,y=c]{data.txt};
        \addplot[red, mark=x] coordinates {(3,6)};
        \addplot[mark=*] coordinates {(8,16)};

        \legend{Z}
   \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

1

You can add scatter to enable modifying markers appearance and a scatter/classes like this

\begin{filecontents*}{data.txt}
A C  label
1 2  a
2 4  a
3 6  b
4 8  a
5 10 a
6 12 a
7 14 a
8 16 c
9 18 a
10 20 a
\end{filecontents*}

\documentclass[paper=a4,ngerman,xcolor=dvipsnames]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\pgfplotscreateplotcyclelist{mycolorlist}{
blue!50!green,every mark/.append style={fill=blue!10!black},mark=x\\
}   

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        grid=both,
        width=12cm, 
        height=9cm,
        xtick pos=left,
        ytick pos=left,
        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={
          a={},% empty argument means: use the default style       
          b={red},
          c={mark=*,black}
            },
        ]

\addplot table [x=A,y=C,meta=label] {data.txt};


            \legend{Z}
        \end{axis}
    \end{tikzpicture}
\end{document}
1
  • Thanks @Salim Bou "scatter" works fine for me! But the markers,which differ from the default style, appear in my legend. Is there a possibility to get rid of them?
    – Björn
    Jan 11, 2017 at 9:55

You must log in to answer this question.

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