Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried to plot a scatterplot from data. I took hint from the site http://pgfplots.sourceforge.net/gallery.html and my tex file is

\documentclass[a4paper]{amsart}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[finnish]{babel}
\usepackage{url}
\usepackage{parskip} % Tyhjä rivi kappaleiden väliin.
\usepackage{booktabs}
\usepackage{tikz,pgfplots}
\renewcommand*\arraystretch{2}
\listfiles
\begin{document}

\begin{tikzpicture}
\begin{axis}[%
scatter/classes={%
    a={mark=o,draw=black}}]
\addplot[scatter,only marks,%
    scatter src=explicit symbolic]%
table[meta=label] {
x y label
1 4.3 a
2 5.1 a
3 5.7 a
4 6.3 a
5 6.8 a
6 7.1 a
7 7.2 a
8 7.2 a
9 7.2 a
10 7.2 a
11 7.5 a
12 7.8 a
    };
\end{axis}
\end{tikzpicture}
\end{document}

However, LaTeX said the following:

    ! Package pgfplots Warning: You requested to open table ' x y label 1 4.3 a 2 5
    .1 a 3 5.7 a 4 6.3 a 5 6.8 a 6 7.1 a 7 7.2 a 8 7.2 a 9 7.2 a 10 7.2 a 11 7.5 a 
    12 7.8 a ', but there is also a ' x y label 1 4.3 a 2 5.1 a 3 5.7 a 4 6.3 a 5 6
    .8 a 6 7.1 a 7 7.2 a 8 7.2 a 9 7.2 a 10 7.2 a 11 7.5 a 12 7.8 a .tex'. TeX will
     automatically append the suffix '.tex', so I will now open ' x y label 1 4.3 a
     2 5.1 a 3 5.7 a 4 6.3 a 5 6.8 a 6 7.1 a 7 7.2 a 8 7.2 a 9 7.2 a 10 7.2 a 11 7.
    5 a 12 7.8 a .tex'. Please make sure you don't accidentally load TeX files - th
    is may produce unrecoverable errors.
    ! Extra \or.
    <argument> ...dcsname \end \pgfplotstable@EOI \or 
                                                      \let \pgfplotstableread@im...
    l.33     };

    ? x

Log file gives:

File: tikzlibrarytopaths.code.tex 2008/06/17 v2.10 (rcs-revision 1.2)
))) (/usr/share/texmf-texlive/tex/latex/pgfplots/pgfplots.sty
Package: pgfplots 2009/02/14 Version 1.2.2

(/usr/share/texmf-texlive/tex/generic/pgfplots/pgfplots.code.tex
(/usr/share/texmf-texlive/tex/generic/pgfplots/pgfplotscore.code.tex
\t@pgfplots@toka=\toks37
\t@pgfplots@tokb=\toks38
\t@pgfplots@tokc=\toks39
\pgfplots@tmpa=\dimen173
)
(/usr/share/texmf-texlive/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsup
p_loader.code.tex
Package pgfplots: loading complementary code for your PGF version...

(/usr/share/texmf-texlive/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsup
p_misc.code.tex)
(/usr/share/texmf-texlive/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsup
p_pgfkeysfiltered.code.tex
\pgfkeys@tmptoks=\toks40
)
(/usr/share/texmf-texlive/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsup
p_pgfmathfloat.code.tex
\c@pgfmathroundto@lastzeros=\count124
)
(/usr/share/texmf-texlive/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsup
p_pgflibraryplothandlers.code.tex
File: pgfplotsoldpgfsupp_pgflibraryplothandlers.code.tex 2009/02/13 v2.10 (rcs-
revision 1.7)
\pgf@plot@mark@count=\count125
\pgfplotmarksize=\dimen174
)
(/usr/share/texmf/tex/generic/pgf/libraries/pgflibraryfpu.code.tex))
(/usr/share/texmf-texlive/tex/generic/pgfplots/util/pgfplotsutil.code.tex
(/usr/share/texmf-texlive/tex/generic/pgfplots/liststructure/pgfplotsliststruct
ure.code.tex)
(/usr/share/texmf-texlive/tex/generic/pgfplots/liststructure/pgfplotsliststruct
ureext.code.tex)
(/usr/share/texmf-texlive/tex/generic/pgfplots/liststructure/pgfplotsarray.code
.tex
\c@pgfplotsarray@tmp=\count126
)
(/usr/share/texmf-texlive/tex/generic/pgfplots/numtable/pgfplotstable.code.tex
\c@pgfplotstable@counta=\count127
\pgfplotstable@outfile=\write4

(/usr/share/texmf-texlive/tex/generic/pgfplots/numtable/pgfplotstable.coltype.c
ode.tex)))
(/usr/share/texmf-texlive/tex/generic/pgfplots/util/pgfplotscolormap.code.tex)
(/usr/share/texmf-texlive/tex/generic/pgfplots/pgfplots.stackedplots.code.tex)
(/usr/share/texmf-texlive/tex/generic/pgfplots/pgfplotscoordprocessing.code.tex
) (/usr/share/texmf-texlive/tex/generic/pgfplots/pgfplotsticks.code.tex)
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecor
ations.code.tex
(/usr/share/texmf/tex/generic/pgf/modules/pgfmoduledecorations.code.tex
\pgfdecoratedcompleteddistance=\dimen175
\pgfdecoratedremainingdistance=\dimen176
\pgfdecoratedinputsegmentcompleteddistance=\dimen177
\pgfdecoratedinputsegmentremainingdistance=\dimen178
\pgf@decorate@distancetomove=\dimen179
\pgf@decorate@repeatstate=\count128
\pgfdecorationsegmentamplitude=\dimen180
\pgfdecorationsegmentlength=\dimen181
)
\tikz@lib@dec@box=\box38
)
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecor
ations.pathmorphing.code.tex
(/usr/share/texmf/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.p
athmorphing.code.tex))
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecor
ations.pathreplacing.code.tex
(/usr/share/texmf/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.p
athreplacing.code.tex))
\pgfplots@numplots=\count129
\pgfplots@xmin@reg=\dimen182
\pgfplots@xmax@reg=\dimen183
\pgfplots@ymin@reg=\dimen184
\pgfplots@ymax@reg=\dimen185
\pgfplots@zmin@reg=\dimen186
\pgfplots@zmax@reg=\dimen187
)
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryplotm
arks.code.tex
File: tikzlibraryplotmarks.code.tex 2008/01/09 v2.10 (rcs-revision 1.1)

So, what is an easy way to draw scatter plots in LaTeX? And how can I add a regression line to the plot?

Update: These are the versions of files I'm using:

grep File testi.log
File: amsgen.sty 1999/11/30 v2.0
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
File: utf8.def 2008/04/05 v1.1m UTF-8 support for inputenc
File: t1enc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
File: ot1enc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
File: omsenc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
File: t1enc.def 2005/09/27 v1.99g Standard LaTeX file
File: babel.def 2008/07/06 v3.8l Babel common definitions
File: graphics.cfg 2009/08/28 v1.8 graphics configuration of TeX Live
File: dvips.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
File: pgf.cfg 2008/05/14  (rcs-revision 1.7)
File: pgfsys-dvips.def 2008/04/03  (rcs-revision 1.20)
File: pgfsys-common-postscript.def 2008/10/01  (rcs-revision 1.22)
File: pgfsyssoftpath.code.tex 2008/07/18  (rcs-revision 1.7)
File: pgfsysprotocol.code.tex 2006/10/16  (rcs-revision 1.4)
File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
File: pgfcorepoints.code.tex 2010/04/09  (rcs-revision 1.20)
File: pgfcorepathconstruct.code.tex 2010/08/03  (rcs-revision 1.24)
File: pgfcorepathusage.code.tex 2008/04/22  (rcs-revision 1.12)
File: pgfcorescopes.code.tex 2010/09/08  (rcs-revision 1.34)
File: pgfcoregraphicstate.code.tex 2008/04/22  (rcs-revision 1.9)
File: pgfcoretransformations.code.tex 2009/06/10  (rcs-revision 1.11)
File: pgfcorequick.code.tex 2008/10/09  (rcs-revision 1.3)
File: pgfcoreobjects.code.tex 2006/10/11  (rcs-revision 1.2)
File: pgfcorepathprocessing.code.tex 2008/10/09  (rcs-revision 1.8)
File: pgfcorearrows.code.tex 2008/04/23  (rcs-revision 1.11)
File: pgfcoreshade.code.tex 2008/11/23  (rcs-revision 1.13)
File: pgfcoreimage.code.tex 2010/03/25  (rcs-revision 1.16)
File: pgfcoreexternal.code.tex 2010/09/01  (rcs-revision 1.17)
File: pgfcorelayers.code.tex 2010/08/27  (rcs-revision 1.2)
File: pgfcoretransparency.code.tex 2008/01/17  (rcs-revision 1.2)
File: pgfcorepatterns.code.tex 2009/07/02  (rcs-revision 1.3)
File: pgfmoduleshapes.code.tex 2010/09/09  (rcs-revision 1.13)
File: pgfmoduleplot.code.tex 2010/10/22  (rcs-revision 1.8)
File: pgflibraryplothandlers.code.tex 2010/05/31 v2.10 (rcs-revision 1.15)
File: pgfmodulematrix.code.tex 2010/08/24  (rcs-revision 1.4)
File: tikzlibrarytopaths.code.tex 2008/06/17 v2.10 (rcs-revision 1.2)
File: pgfplotsoldpgfsupp_pgflibraryplothandlers.code.tex 2009/02/13 v2.10 (rcs-
File: tikzlibraryplotmarks.code.tex 2008/01/09 v2.10 (rcs-revision 1.1)
File: pgflibraryplotmarks.code.tex 2010/10/15 v2.10 (rcs-revision 1.12)
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
File: umsb.fd 2009/06/22 v3.00 AMS symbols B
share|improve this question
1  
It would be easier to help you if you could clean up your code by deleting all the things that are not needed here, making your example really minimal (see minimal working example (MWE)). Anyway, as is stands, your code compiles fine here. Are your packages up-to-date? –  Corentin Oct 16 '12 at 12:44
    
@Corentin I downloaded those with apt-get and I'm using Ubuntu 12.04.1 LTS so I guess the packages are up-to-date. –  Jaakko Seppälä Oct 16 '12 at 12:56
    
The list I gave below is based on @Corentin's solution. You should compare your list with what I have below and see that you have much older versions. I'd recommend you install TeXLive 2012 and go from there, but if you don't want to do that you need to update your packages at least. –  Peter Grill Oct 18 '12 at 17:30

2 Answers 2

I think you are missing a label column. The following MWE works fine here:

\documentclass{article}

\usepackage{tikz,pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
scatter/classes={%
    a={mark=o,draw=black}}]
\addplot[scatter,only marks,%
    scatter src=explicit symbolic]%
table[meta=label] {
x y label
1 4.3 a
2 5.1 a
3 5.7 a
4 6.3 a
5 6.8 a
6 7.1 a
7 7.2 a
8 7.2 a
9 7.2 a
10 7.2 a
11 7.5 a
12 7.8 a
    };
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
No, ! Package pgfkeys Error: I do not know the key '/tikz/scatter src' and I am goi ng to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H <return> for immediate help. ... l.85 \end{axis} ? –  Jaakko Seppälä Oct 16 '12 at 12:25
    
@JaakkoSeppälä Looks like you are supplying the options to the tikzpicture environment instead of axis environment –  percusse Oct 16 '12 at 12:36
    
I added label but now it says ! Extra \or. <argument> ...dcsname \end \pgfplotstable@EOI \or \let \pgfplotstableread@im... l.88 }; –  Jaakko Seppälä Oct 16 '12 at 12:38
    
@percusse Probably. I haven't used neither axis nor tikzpicture before. –  Jaakko Seppälä Oct 16 '12 at 12:42
    
@JaakkoSeppälä If you just copy and paste my code (with no other addition), does it work on your machine? –  Corentin Oct 16 '12 at 12:46
up vote 0 down vote accepted

The problem might be in the combination of Ubuntu 12.04 and Texlive 2009. As I upgraded my software to Ubuntu 12.10 and Texlive 2012 and compile file by command pdflatex test.tex, I can see the correct picture in Ghostview.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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