# Alternative for drawing graphs?

I've been trying to draw a graph with a series of X,Y points in TikZ, but it won't accept my points so I'm seeking an alternative package that might handle scaling a bit better. The kind of points i've been trying to graph are imported from a text file and look something like:

0 -5181.542311
0.001388889 -5180.244522
0.002777778 -5176.351945
0.004166667 -5169.866943
0.005555556 -5160.793459
0.006944444 -5149.137011
0.008333333 -5134.904699
0.009722222 -5118.1052
0.011111111 -5098.748774
...


Any ideas on suitable alternatives for this kind of data?

-
Ah, well, those are the wrong sort of points ... seriously, it would be useful to see what your code is that didn't work with those points. –  Loop Space Feb 14 '12 at 18:01
Why wouldn't TikZ "accept" your points? Is there any error message? What kind of plot are you trying to achieve? Please provide more information. –  dhst Feb 14 '12 at 18:06
You need to normalize your data. –  Yiannis Lazarides Feb 14 '12 at 18:14
AndrewStacey, the ... was meant to indicate that there were alot more (720 points in total). @Daniel, the code I tried to use was: \usepackage{tikz} \documentclass{article} \begin{document} \begin {tikzpicture} \draw plot[yscale=0.001,mark=x,smooth] file {swaccdata.table}; \end {tikzpicture} \end{document} –  Andy Feb 14 '12 at 19:57

Without more details of exactly what you attempted and the associated error messages it is difficult to pinpoint why tikz won't accept the points.

Here is an example of using \pgfplotstableread to read in the data from an external file. Here I used the filecontents package to create the external file and package this into a compilable example, but if you already have the data in an external file, this is not needed.

\documentclass{article}
\usepackage{pgfplots}

\usepackage{filecontents}
\begin{filecontents*}{data.dat}
0 -5181.542311
0.001388889 -5180.244522
0.002777778 -5176.351945
0.004166667 -5169.866943
0.005555556 -5160.793459
0.006944444 -5149.137011
0.008333333 -5134.904699
0.009722222 -5118.1052
0.011111111 -5098.748774
\end{filecontents*}
%
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [blue, ultra thick, smooth] table {\MyDataTable};
\end{axis}
\end{tikzpicture}
\end{document}

-
Thanks Peter, that's great, can smooth be used in the [blue, ultra thick] command? –  Andy Feb 14 '12 at 20:03
@Andy: Don't see any reason you should not be able to do that. Did you encounter a problem when you tried? –  Peter Grill Feb 14 '12 at 20:08
I was adding it in the wrong place, sorted that bit now. –  Andy Feb 14 '12 at 22:04
@Andy: Have added that option to the example. –  Peter Grill Feb 15 '12 at 2:30

Asymptote may provide the results you want. It's syntax is C-like, but not terribly difficult. It lends itself very well to graphing lines and numbers and the like. The gallery of 2D graphs on their website may give you a good idea of what it can do and if it will meet your needs.

-

There are many alternative tools that can do the sort of things that you are after but I would personally discourage you from switching from TikZ (for the record I do not use TikZ except in very rare occasions). TikZ is very powerfull and can easily solve your problem. You are never going to become master of anything if you dump the tool as soon as you encounter the smallest obstacle. That been said probably the simplest solution for you is to use MATLAB language. I think I could probably write 3-5 lines script which will do what you want. You could execute the script in one of MATLAB free clones if you do not have the real thing (my favorite is FreeMat). Slightly more complicated is to use Python's Matplotlib. Then even more complicated is to use PSTricks. Then somebody already suggested Asymptote (has C++/Java like syntax which is which is a big turn off for people like me who hate Java). You can think of it as MetaPost on steroids which also can be used. I am sure it can be done using some Perl, Ruby, Lua libraries (insert your favorite scripting language). You can do even in pure C if you a masochist (I love C and use it every day but it is not created for that).

-
Thank you for such a detailed reply, I think you're right on the point with sticking with TikZ, although I've only been using it for a couple of days now i've been able to create some nice diagrams with it (although not particularly efficiently judging by other example i've seen). –  Andy Feb 14 '12 at 20:06
@Andy I think you should also have a look at pgfplots which is equivalently beautiful and much powerful when it comes to plotting data. Naturally supports TikZ/PGF since it is built on top of it. –  percusse Feb 15 '12 at 0:00

I would recommend using the statistical programming language R, which I have been using for many years now. It is open source, and thus freely available. It also has a very active user community. Especially the ggplot2 package provides an awesome way of visualizing data, not just drawing pictures. There is a video on youtube by the author of ggplot2 which provides some background. See also the documentation on the webpage of ggplot2 to see a lot of examples.

The basic workflow than becomes making an illustration in R, generating a pdf, and including this pdf into latex.

An added advantage of learning R it can do a lot more than just make illustrations. This includes data processing, statistical analyses and much more.

-