2

I'm trying to create a simple dot-plot using pgf-plots. When I try to build the file, I get several Missing number, treated as zero errors on the \end{axis} line.


\documentclass[]{article}

\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{width=10cm, compat=1.12}

%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{tikzpicture}
    \begin{axis}[
    mark=*,
    width=10.0cm,
    height=1.0cm,
    axis y line = none,
    axis x line = bottom,
    xtick={1, 10},
    ymin=0.0,
    ymax=1.5,
    xmin=1.0,
    xmax=10.0, 
    scale only axis
    ]
    \addplot+[scatter,only marks,
    scatter src=explicit symbolic]
    coordinates {(1, 1) (2, 1) (3, 1) (4, 1) (5, 1) (6, 1) (7, 1) (8, 1) (9, 1) (10, 1)};
    \end{axis}
\end{tikzpicture}

\end{document}

Why am I getting the Missing number, treated as zero error?

Also, if anyone knows a better way to make better looking dot plots, I'd love to know.

Thanks a million!

2
  • 1
    I don't get exactly that error, but what happens if you remove scatter src=explicit symbolic? – Torbjørn T. Sep 22 '16 at 8:04
  • D'oh. That's it. I removed that and it worked. I was copying code from another person's website and didn't know what was required and what wasn't. I'm not even sure what src=explicit symbolic even means. Thanks a lot, Torbjorn – Brent Parker Sep 22 '16 at 8:18
2

With scatter src=explicit or scatter src=explicit symbolic it is expected that there is a third data point. See the description of the scatter src key in the pgfplots manual. As you only have x and y coordinates, if you simply remove scatter src=explicit the code works.

One use case for scatter src is shown below, where the third data point is used to determine the type of marker used. Note the way coordinates are written, (x,y) [meta].

enter image description here

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{width=10cm, compat=1.12}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
    mark=*,
    width=10.0cm,
    height=1.0cm,
    axis y line = none,
    axis x line = bottom,
    xtick={1,10},
    ymin=0.0,
    ymax=1.5,
    xmin=1.0,
    xmax=10.0, 
    scale only axis
    ]
    \addplot+[scatter,only marks,
    scatter src=explicit symbolic,
    scatter/classes={
        a={mark=square,red},
        b={mark=*,blue}}
]
  coordinates {
  (1, 1) [a]
  (2, 1) [b]
};
    \end{axis}
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.