Discussion:
export plot data
(too old to reply)
grimal
2004-04-29 23:41:26 UTC
Permalink
message to the list

Dear list members,

I have developed a Mathematica notebook with a Plot command at the end.
The evaluation of Plot[f,{x,xmin,xmax}] involves a function f that is
defined in the notebook; xmin and xmax are also functions defined in the
notebook and evaluated while doing the Plot.
I am satisfied with the result of the Plot command.

Now, I would like to export in a txt file the data (list of points)
generated during the evaluation of the Plot. Then I could use the list
of points to plot the data with another software.
I have tried the Table command to generate a list but it does not seem
to work.
Can anybody help me?

Thanks

Quentin Grimal
David Park
2004-04-30 23:44:43 UTC
Permalink
Quentin,

An example:

plot1 = Plot[Sin[x], {x, 0, 2Pi}];

The primitive graphics for the curve is in

First[plot1]

You could extract the points that Mathematica used by

***@Cases[plot1, Line[points_] -> points, Infinity]

David Park
***@earthlink.net
http://home.earthlink.net/~djmp/

From: grimal [mailto:***@univ-paris12.fr]

Dear list members,

I have developed a Mathematica notebook with a Plot command at the end.
The evaluation of Plot[f,{x,xmin,xmax}] involves a function f that is
defined in the notebook; xmin and xmax are also functions defined in the
notebook and evaluated while doing the Plot.
I am satisfied with the result of the Plot command.

Now, I would like to export in a txt file the data (list of points)
generated during the evaluation of the Plot. Then I could use the list
of points to plot the data with another software.
I have tried the Table command to generate a list but it does not seem
to work.
Can anybody help me?

Thanks

Quentin Grimal
Jens-Peer Kuska
2004-04-30 23:50:48 UTC
Permalink
Hi,

plt = Plot[Sin[x], {x, 0, Pi}];
Export["tmp.txt",
First[Cases[plt, _Line, Infinity] /. Line[pnts_] :> pnts], "Table"]

Regards
Jens
Post by grimal
message to the list
Dear list members,
I have developed a Mathematica notebook with a Plot command at the end.
The evaluation of Plot[f,{x,xmin,xmax}] involves a function f that is
defined in the notebook; xmin and xmax are also functions defined in the
notebook and evaluated while doing the Plot.
I am satisfied with the result of the Plot command.
Now, I would like to export in a txt file the data (list of points)
generated during the evaluation of the Plot. Then I could use the list
of points to plot the data with another software.
I have tried the Table command to generate a list but it does not seem
to work.
Can anybody help me?
Thanks
Quentin Grimal
Brian Higgins
2004-05-01 00:00:59 UTC
Permalink
Quentin,

Here is one way:

First create a empty text file in your favorite directory; call it
mydata.txt (for this example). then evaluate

plt1 = Plot[Sin[x], {x, 0, 2Pi}]
mydata = Flatten[Cases[plt1, Line[x__] -> x, Infinity], 1];

Now to export the data as CSV to the file you created previous then
type

Export["/Users/brian/Desktop/mydata.txt", mydata, "CSV"]

The first argument of Export is the filename and path that you wish to
export your data. To get that info automatically place your cursor
after "[" and then from the file menu select Input and then select
"Get File Path.." A dialog box will open that will allow you to
navigate to the file you created in Step 1. Select the file mydata.txt
and the click on the Choose button. The appropriate path plus file
name will be pasted as the first argument of Export.

Note in the above example I used a mac with OSX. In windows the
filepath syntax involves "\\" values rather than "/" values to delimit
directories.

If you simple type in "mydata.txt" as the first argument of Export the
file is created in the default directory of Mathematica

You can then open the file in Excel or other software thar recognizes
CSV data

Cheers,

Brian
Post by grimal
message to the list
Dear list members,
I have developed a Mathematica notebook with a Plot command at the end.
The evaluation of Plot[f,{x,xmin,xmax}] involves a function f that is
defined in the notebook; xmin and xmax are also functions defined in the
notebook and evaluated while doing the Plot.
I am satisfied with the result of the Plot command.
Now, I would like to export in a txt file the data (list of points)
generated during the evaluation of the Plot. Then I could use the list
of points to plot the data with another software.
I have tried the Table command to generate a list but it does not seem
to work.
Can anybody help me?
Thanks
Quentin Grimal
Continue reading on narkive:
Loading...