2

I want to do something simple. I have the following data in a text file called example.txt:

a 1.254 b 0.995 c 2.782
d 5.722

I want to plot all the data with a, b, c and on X axis but pgfplots think first line is a header so I want to use header=false to consider the first row (what I put in comment) but I get the error "tikz does not know header".

Here my code:

\documentclass[11pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}


\begin{tikzpicture} 
\begin{axis}[ 
ylabel={Y}, 
xlabel={X}, 
symbolic x coords={a,b,c,d}, 
xtick={a,b,c,d},
xticklabels={AAAA,BBBB, CCCC,DDDD} 
] 
\addplot +[only marks,color=red] table {example.txt}; 
%\addplot +[header=false,only marks,color=red] table {example.txt}; 
\end{axis} 
\end{tikzpicture}

\end{document}  

Thank you in advance!!

  • 1
    \addplot +[only marks,color=red] table[header=false,] {example.txt};, i.e. pass header=false to the table, not to the plot. – marmot Jan 31 at 20:49
  • I knew it was something simple.... thank you for the fast answer! – Willi Jan 31 at 20:51
  • @CarLaTeX Done. I'll be happy to remove it if other users feel it should not be there. – marmot Feb 1 at 4:44
  • 1
    Good find! Do you want to close your question as a duplicate of tex.stackexchange.com/questions/29063/… ? I believe that your question is still very useful since, as long as one does not know the root of the problem, it is hard to know which key words one should look for, and once you know, you do no longer ask. – marmot Feb 1 at 16:16
2

I will be happy to remove this if you feel like you want to delete your question, and I am writing this because @CarLaTeX asked me to.

Answer to the question

You need to put header=false to the options of the table, not the plot.

Side remark

You make things slightly easier for others if you use filecontents to add the data. That way you may attract more users to play with the code.

\documentclass[11pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\usepackage{filecontents}
\begin{filecontents*}{example.txt}
a 1.254 
b 0.995 
c 2.782
d 5.722
\end{filecontents*}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[ 
ylabel={Y}, 
xlabel={X}, 
symbolic x coords={a,b,c,d}, 
xtick={a,b,c,d},
xticklabels={AAAA,BBBB, CCCC,DDDD} 
] 
\addplot +[only marks,color=red] table[header=false] {example.txt}; 
\end{axis} 
\end{tikzpicture}
\end{document}  

enter image description here

  • Even my question was (a bit) stupid ^^, I am using quite a lot pgfplots but this time I was not used to this case were options are set for the table, so I think it may help other people. If you think it was just a too silly question, I have no problem if you want to "clean" the content of tex.stackechange ;-) – Willi Feb 1 at 8:05
  • @Willi I apologize if I made the impression that your question is stupid, it is certainly not. I am more worried that it is likely a duplicate, but the earlier posts are hard to find. – marmot Feb 1 at 10:20
  • no actually it was written there: tex.stackexchange.com/questions/29063/… but I must have been tired and I did not notice the position of options (concerning the table and not addplot) – Willi Feb 1 at 10:37

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.