1

I have to create a bunch of scatter plots and I would like to avoid having to manually redefine the markers for all of the plots each time I decide that it does not look good enough... anyways, I see how to do this with the line included in this post, but I cannot figure it out when I want to use \addplot[only marks]

here is the MWE of the manual way

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{figure}
    \begin{tikzpicture}
    \begin{axis}[]
    \addplot[blue, only marks,mark=*] 
    coordinates{(1,2)(2,3)};
    \addplot[red, only marks,mark=square*]
    coordinates{(1.2,2.2)(2.2,3.2)};
    \end{axis}
    \end{tikzpicture}
    \end{figure}
\end{document}

OR... is there a way to somehow turn off the line that goes through the marker and use \pgfplotscreateplotcyclelist{}

Thanks!

3
  • Your MWE isn't a complete MWE. It lacks \documentclass, the used packages and \begin{document}, \end{document}.
    – Skillmon
    Jan 10, 2018 at 19:28
  • @Skillmon fine for me but I don't understand the question.
    – percusse
    Jan 10, 2018 at 19:29
  • @percusse, so instead of the MWE, I want to be able to define a single list of markers at the start of my code that defines all of the markers in the rest of the code Jan 10, 2018 at 19:32

1 Answer 1

3

You need to use \addplot+[only marks]:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
  \begin{axis}[]
  \addplot+[only marks] 
  coordinates{(1,2)(2,3)};
  \addplot+[only marks]
  coordinates{(1.2,2.2)(2.2,3.2)};
  \end{axis}
  \end{tikzpicture}
\end{document}

The + makes \addplot use all the default options (cycling through the markers) plus the options you specify (only marks).

To further shorten that, if you want to use the option only marks on each \addplot inside a tikzpicture you can use:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[only marks]
  \begin{axis}[]
  \addplot
  coordinates{(1,2)(2,3)};
  \addplot
  coordinates{(1.2,2.2)(2.2,3.2)};
  \end{axis}
  \end{tikzpicture}
\end{document}

Alternatively you can also give this as an option to axis (\begin{axis}[only marks]).

To change the cycle list used you can use the option cycle list name=<name> in the options of axis. Predefined cycle list are listed in the corresponding section of the package documentation.

You can also provide your own cycle list:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[]
  \begin{axis}[only marks,
      cycle list={
        {blue,mark=*},
        {red,mark=square*,mark options={fill=green}},
        {mark=o},
        {yellow,mark=+},
      }
    ]
  \addplot
  coordinates{(1,2)(2,3)};
  \addplot
  coordinates{(1.2,2.2)(2.2,3.2)};
  \end{axis}
  \end{tikzpicture}
\end{document}

And lastly: You can save this cycle list with a name to reuse it with the cycle list name key:

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotscreateplotcyclelist{foo}{
        {blue,mark=*},
        {red,mark=square*,mark options={fill=green}},
        {mark=o},
        {yellow,mark=+},
      }
\begin{document}
\begin{tikzpicture}[]
  \begin{axis}[only marks,
      cycle list name=foo
    ]
  \addplot
  coordinates{(1,2)(2,3)};
  \addplot
  coordinates{(1.2,2.2)(2.2,3.2)};
  \end{axis}
  \end{tikzpicture}
\end{document}

You could as well specify the only marks key in each of the elements of that \pgfplotscreateplotcyclelist (or just in some).

0

You must log in to answer this question.

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