Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
Could you post an example plot? –  David G. Stork 23 hours ago
2  
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 23 hours ago
    
    
Related, if not a duplicate. –  march 21 hours ago

2 Answers 2

up vote 10 down vote accepted

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

share|improve this answer
    
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 22 hours ago
    
@anderstood. Agreed. I will edit as necessary. –  march 22 hours ago
    
Thanks both – this has saved me! –  Will Vousden 21 hours ago
  • 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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