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 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}

enter image description here

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.

share|improve this question
    
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 '13 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 '13 at 17:35
    
To clarify, I don't want to write file {doses.data};, but the contents of doses.data instead. –  Eekhoorn Jan 20 '13 at 17:47

1 Answer 1

up vote 3 down vote accepted

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}
    # Header goes here
    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.

share|improve this answer
    
I went with the first version, once typed in, I don't need to change the coordinates. –  Eekhoorn Jan 20 '13 at 19:03

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.