13
$\begingroup$

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[[1]], PlotStyle -> data[[2]], 
      Joined -> True], {data, dataSets[[2 ;;]]}];

Example plot

$\endgroup$
  • $\begingroup$ Could you post an example plot? $\endgroup$ – David G. Stork Sep 11 '15 at 17:50
  • 2
    $\begingroup$ 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! $\endgroup$ – march Sep 11 '15 at 17:50
  • $\begingroup$ related mathematica.stackexchange.com/q/38257/2079 $\endgroup$ – george2079 Sep 11 '15 at 19:01
  • $\begingroup$ Related, if not a duplicate. $\endgroup$ – march Sep 11 '15 at 19:06
15
$\begingroup$

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

enter image description here

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

enter image description here

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – anderstood Sep 11 '15 at 18:18
  • $\begingroup$ @anderstood. Agreed. I will edit as necessary. $\endgroup$ – march Sep 11 '15 at 18:18
  • $\begingroup$ Thanks both – this has saved me! $\endgroup$ – Will Vousden Sep 11 '15 at 19:42
  • $\begingroup$ @Ruslan . I think those points were addressed in the second part of my post? $\endgroup$ – march Jan 15 '17 at 16:38
  • $\begingroup$ Oh indeed, hadn't read up to there :) $\endgroup$ – Ruslan Jan 15 '17 at 17:18
7
$\begingroup$
  • First step for illustration purpose : generate an image

MoneyPlot[{{{1, 2, 6}, {6, 3, 3}}}, 0, 0]

enter code here

  • 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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