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?

  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Aug 31, 2016 at 16:32
  • 1
    $\begingroup$ The plots in Mathematica are extremely customizable. Have you considered tweaking the many formatting options to create a style that suits you or using one of the many build in PlotThemes? These too can be customized through the plot function's options. $\endgroup$
    – Edmund
    Commented Aug 31, 2016 at 19:36
  • 1
    $\begingroup$ With the possible exception of the typesetting component, I agree with @Edmund. So ... maybe you could post an example of an aesthetic plot that you feel is hard to produce with WL. $\endgroup$
    – Alan
    Commented Aug 31, 2016 at 23:40
  • $\begingroup$ This solves my problem. However, is there a way to get the output in the same format? All the x and y values with the same significant figures for instance. $\endgroup$ Commented Sep 2, 2016 at 7:44

2 Answers 2


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


An alternative

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


enter image description here


{{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"]
  • 2
    $\begingroup$ Plot chooses its point adaptively, so your method will not yield the same point set. $\endgroup$ Commented Aug 31, 2016 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.