3

I'm getting the error message:

! Package PGF Math Error: Could not parse input 'a' as a floating point number, sorry. The unreadable part was near 'a'..

Somehow the table cannot be read. I would like to have an axis with colored points on them. The first part worked until I added the scatter/classes and table thing.

\documentclass{article}
\usepackage{tikz, pgfplots}
\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            axis x line=center,
            axis y line=none,
            hide y axis,
            xmin=0,xmax=20,
            ymin=0, ymax=1,
            xtick={0,...,20},
            xticklabels={,,}
            scatter/classes={%
                a={mark=o,draw=blue},
                b={mark=o,draw=red}}]

        \addplot[scatter,only marks,%
            scatter src=explicit symbolic]%
        table[meta=label]{
            x   label
            1   a
            2   a
            3   a
            4   a
            6   a
            13  a
            10  b
            14  b
            17  b
            18  b
        };
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

Working example without a plot:

\documentclass{article}
\usepackage{tikz, pgfplots}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            axis x line=center,
            axis y line=none,
            hide y axis,
            xmin=0,xmax=20,
            ymin=0, ymax=1,
            xtick={0,...,20},
            xticklabels={,,},
            scatter/classes={%
                a={mark=o,draw=blue},
                b={mark=o,draw=red}}]
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Jul 28 '17 at 14:06
  • 1
    You need to add a y column consisting of 0. – Symbol 1 Jul 28 '17 at 15:13
  • @Symbol1 unfortunately the same error persists – rattletat Jul 28 '17 at 15:31
  • 1
    And also at the end of xticklabels={,,} you missed a comma. – Symbol 1 Jul 28 '17 at 15:43
  • @Symbol1 Thank you!! That fixed it. – rattletat Jul 28 '17 at 16:09
1

@Symbol1 fixed this in the comments. Here's the working code.

\documentclass{article}
\usepackage{tikz, pgfplots}
\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            axis x line=center,
            axis y line=none,
            hide y axis,
            xmin=0,xmax=20,
            ymin=0, ymax=1,
            xtick={0,...,20},
            xticklabels={,,},
            scatter/classes={%
                a={mark=o,draw=blue},
                b={mark=o,draw=red}}]

        \addplot[scatter,only marks,%
            scatter src=explicit symbolic]%
        table[meta=label]{
            x   y   label
            1   0   a
            2   0   a
            3   0   a
            4   0   a
            6   0   a
            13  0   a
            10  0   b
            14  0   b
            17  0   b
            18  0   b
        };
        \end{axis}
    \end{tikzpicture}
\end{figure}
\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.