Hallo,
I want to make a plot with vectors going from the coordinate specified in file1 to the coordinate in file2. Can I do this with PGF/Tikz? (Making \draw (x1,y1) -- (x2,y2); is not an option, each file contains 200+ lines.) The files are in the format:
x1 y1
x2 y2
.
.
.
All ideas are welcome!
Graphics, Figures & Tables ⇒ Tikz and multiple input files
Tikz and multiple input files
Last edited by Anicka on Wed Feb 23, 2011 3:48 pm, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

Tikz and multiple input files
I'm assuming that your two files (call them file1 and file2) have the same number of lines, and in each file the two coordinates are separated by a single space. If so, then if you're on a UNIX-like system an easy way would be to use some UNIX shell utilities (paste and awk) in a terminal window:
I tested that on a file1 with these 3 lines
and a file2 with these 3 lines:
and it produced the file mycoords.tex consisting of these TikZ commands:
You could then use \input{mycoords} inside a tikzpicture environment (or copy and paste the contents). There may be a slicker way of having TikZ do it programmatically, but this is my quick and dirty solution. 
Code: Select all
paste file1 file2 | awk '{print "\\draw[->] ("$1","$2") -- ("$3","$4");"}' > mycoords.tex
Code: Select all
1 2
4 3
5 0
Code: Select all
7 8
10 9
11 0
Code: Select all
\draw[->] (1,2) -- (7,8);
\draw[->] (4,3) -- (10,9);
\draw[->] (5,0) -- (11,0);

Re: Tikz and multiple input files
Thanks!
I ended up doing something similar "by hand", using jedit to insert text by the column.
I ended up doing something similar "by hand", using jedit to insert text by the column.