21

Since I do not like the style of the Mathematica plots, I prefer to extract the data points and use other programs to get publish quality plots.

Plot, extract data to a file

In this page, it is explained how to extract data points from already drawn figure in Mathematica. However, this command does not work if the function is piecewise continous. For instance;

data = Cases[Plot[Tan@x, {x, 0, 2 Pi}], Line[data_] :> data, -4, 1][[1]];

Export["file.txt", data, "Table"]

Then the extracted data is up to pi/2 , to the part where the function diverges.

Is there a way to get all the data points that is drawn with Mathematica to get the exact same plot with other programs?

virtual_mind
  • 436
  • 1
  • 3
  • 9

2 Answers2

17

In your Cases command you specifically asked for only the first line. You can grab all the lines, and Catenate the results into a single list

data = Catenate@
   Cases[Plot[Tan@x, {x, 0, 2 Pi}], Line[data_] :> data, Infinity];
Export["file.txt", data, "Table"];
ListPlot[Import["file.txt", "Table"]]

Mathematica graphics

Jason B.
  • 68,381
  • 3
  • 139
  • 286
2

An alternative

points = Table[{x, Tan[x]}, {x, Range[0, 2 π, .01]}];

ListLinePlot[points]

enter image description here

Shallow[points]

{{0., 0.}, {0.01, 0.0100003}, {0.02, 0.0200027}, {0.03, 0.030009}, {0.04, 0.0400213}, {0.05, 0.0500417}, {0.06, 0.0600721}, {0.07, 0.0701146}, {0.08, 0.0801711}, {0.09, 0.0902438}, <<619>>}

So, points is your List, containing 600plus Values. And you can use your strategy to save'em:

Export["points.txt", points, "Table"]