Recovering data from an existing plot

I have some plots in an old Mathematica notebook that I'd like to re-create in Matplotlib (for stylistic consistency with the rest of the plots in my thesis).

Unfortunately, I've lost the data that I used to generate these plots. Since the plots are still intact, is it possible to extract the coordinates of the data points from them? I know that I can use "Get Coordinates" from the context menu on the plot, but this is tedious and imprecise!

They were generated in version 8 or 9, I think. This is the code that I used to generate the plots:

MoneyPlot[dataSets_, Vs_, fs_] :=
Show @@ {ListLogLogPlot[dataSets[[1, 1]],
PlotStyle -> dataSets[[1, 2]],
Joined -> True
(* Some more options *)
]}~Join~
Table[ListLogLogPlot[data[], PlotStyle -> data[],
Joined -> True], {data, dataSets[[2 ;;]]}]; • Could you post an example plot? – David G. Stork Sep 11 '15 at 17:50
• Were these plots made in MMA V6 or later? @DavidG.Stork's question is important, because we need to know what types of plots (Plot, ContourPlot, DensityPlot, etc.) these are, how many traces are shown on each plot, etc. So please post an example! – march Sep 11 '15 at 17:50
• – george2079 Sep 11 '15 at 19:01
• Related, if not a duplicate. – march Sep 11 '15 at 19:06

As explained by anderstood, if you don't have the plots named, you need to copy and paste the figure into an input cell and type, say, fig = in front of the figure, then evaluate.

Suppose you generated a MoneyPlot named fig. Then, you can extract the data making up those curves using

data = Cases[fig // Normal, Line[a_] :> a, Infinity]

In order to test and see if it has extracted correctly, do

ListPlot[#] & /@ data

and you should see a List of Plots, one for each of the curves above.

For the purposes of illustration,

fig = Plot[{x^2, x^3, x^4}, {x, 0, 1}, Frame -> True, GridLines -> Automatic]
data = Cases[fig // Normal, Line[a_] :> a, Infinity];
ListPlot[#] & /@ %

results in Since you have a LogLogPlot, if you want the actual values, rather than the values of the exponents, you just need to wrap data with Exp:

originalValues = Exp[data];

One more thing: this method requires that the points in your figure be Joined, as you've shown. If that is not the case, then you have to extract the Points instead. For instance,

fig = ListLogLogPlot[Table[{x, #}, {x, 0.01, 1, 0.01}] & /@ {x, x^2, x^3}, Frame -> True, GridLines -> Automatic]
data = Cases[fig // Normal, Point[a_] :> a, Infinity];
ListPlot[#] & /@ data
ListPlot[Exp[data]]

results in • I am not sure if he can name the figure fig as, if I understand correctly, he cannot run MoneyPlot since he lost the data. I guess he just has the image saved in a *.nb. The only solution I see is to copy and paste. – anderstood Sep 11 '15 at 18:18
• @anderstood. Agreed. I will edit as necessary. – march Sep 11 '15 at 18:18
• Thanks both – this has saved me! – Will Vousden Sep 11 '15 at 19:42
• @Ruslan . I think those points were addressed in the second part of my post? – march Jan 15 '17 at 16:38
• Oh indeed, hadn't read up to there :) – Ruslan Jan 15 '17 at 17:18
• First step for illustration purpose : generate an image

MoneyPlot[{{{1, 2, 6}, {6, 3, 3}}}, 0, 0] • Copy the plot and paste it instead of PASTE:

fig=PASTE;

• Get the points (in log-log) and take the exponential:

Map[Exp, fig[[1, 2, 3, 4, 1]]]

Output: {{1., 1.}, {2., 2.}, {3., 6.}}

You might have to adjust the indexes in fig.