# Export image data precision

I'm sure there is a very easy way to control this, but I have been searching for an hour now without luck.

I plot a function and export it to get a table that I can use in TikZ.

Plot[{AiryAi[x], AiryBi[x]}, {x, -20, 10}]
Export["airyfunctions.dat", %]


The resulting .dat file has numbers with about 16-17 digits (e.g. 4.044732860029933) whereas I'd like them to have about 5 digits of precision.

Also, the table currently separates the coordinates from the plot like: {x_1,y_1}, {x_2,y_2}, {x_3,y_3}. I'd prefer if they were formatted instead with spaces x_1 y_1 and newlines. I tried using "FieldSeparators" -> " " without luck.

-
Why not plot and export the two Airy functions separately? – J. M. Nov 22 '12 at 2:57
True, I should be doing that. Although I still have the same problems (precision, commas, brackets). – Hanmyo Nov 22 '12 at 4:34
Meh...I made a Perl script to format it the way I want which supports plotting the two Airy functions on the same Plot in Mathematica. Not sure, but plotting them separately might change the data table Mathematica chooses and I'm going to be replotting on same axes... – Hanmyo Nov 22 '12 at 7:39
FWIW: something like N[Round[(* stuff *), 10^-6]] should help with retaining only a fixed number of significant figures... – J. M. Nov 22 '12 at 7:42
I was trying to mess with that but was getting weird stuff because I was trying to apply it to a plot, I think... – Hanmyo Nov 22 '12 at 9:50

I haven't used TikZ, so I don't know how you can deal with the exported data by Export["xxx.txt",data] in TikZ directly. At least, the data exported in this way cannont be used in Origin, because the txt file exported directly as you did, in fact, is the InputForm of plotting the curve in Mathematica.

So, it is necessary to pretreat the Plot result. I do it as follows:

data = Flatten[
List @@@ Select[Flatten[List @@ graph], (Head[#] == Line) &], 2];


where graph is the curve you want to export.

After the pretreatment, use Export["xxx.txt",data,"Table"], and the data will be formatted with spaces and new lines as you wish. But you can only export the two graphs separately.

As for the precision, I cannot figure it out, either. Maybe, after export, using Excel to deal with the precision of exported data is an alternative.

-