# How do I include data files in a TikZ drawing?

I would like to include the following data which is now in a separate doses.data file

0   1
10  1
11  1
12  1
0   2
1   2
4.8 2


into my TikZ drawing. Right now I'm importing the file, but I want the actual data inside my tikzpicture environment:

\documentclass{minimal}
\usepackage{tikz}

%%%<
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{document}
\begin{tikzpicture}[y=.2cm, x=.7cm,font=\rmfamily]
%axis
\draw (0,0) -- coordinate (x axis mid) (21,0);
%ticks
\foreach \x in {0,...,21}
\draw (\x,0pt) -- (\x,-3pt)
node[anchor=north] {\x};
%labels
\node[below=0.8cm] at (x axis mid) {Dose [Gy]};

\draw plot[mark=*, only marks, mark size=2]
file {doses.data};

\end{tikzpicture}
\end{document}


To clarify, I don't want to include file {doses.data};, but the contents of doses.data instead. What is the correct syntax to do this?

Edit: If there's a simpler solution to this with pgfplots, I'm in, but I'd prefer TikZ since I would like to add things later on.

-
You can always use TikZ “to add things later on” with the axis cs coordinate system. (→ pgfplots manual, subsection 4.16.1 “Accessing Axis Coordinates in Graphical Elements”, pp. 255f.) –  Qrrbrbirlbel Jan 20 at 17:18
I'm not sure if I got your question correctly but this might help. It also uses tikzpicture environment. –  Pouya Jan 20 at 17:35
To clarify, I don't want to write file {doses.data};, but the contents of doses.data instead. –  biologue Jan 20 at 17:47

You can embed like this:

\draw plot[mark=*, only marks, mark size=2] coordinates {(0,1) (10,1) (11,1) (12,1) (0,2) (1,2) (4.8,2)};


# OR:

A better way, in which no modification of coordinates is needed:

\documentclass{standalone}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{filecontents}
\begin{filecontents}{doses.data}
0   1
10  1
11  1
12  1
0   2
1   2
4.8 2
\end{filecontents}
\begin{document}
\begin{tikzpicture}[y=.2cm, x=.7cm,font=\rmfamily]
\draw (0,0) -- coordinate (x axis mid) (21,0);
\foreach \x in {0,...,21}
\draw (\x,0pt) -- (\x,-3pt)
node[anchor=north] {\x};
\node[below=0.8cm] at (x axis mid) {Dose [Gy]};
\draw plot[mark=*, only marks, mark size=2] file {doses.data};
\end{tikzpicture}
\end{document}


But this technique still use file. File created by the LaTeX itself on the first run. Standard version of filecontents environment did not update files upon modification of appropriate content, it would be better to use package filecontents which does.

-
I went with the first version, once typed in, I don't need to change the coordinates. –  biologue Jan 20 at 19:03