# Extract function from plot

Consider that we have some plot in Mathematica notebook, like an ordinary plot = Plot[f[x],{x,xmin,xmax},PlotRange->All,PlotLegends->...]. Next, assume that f[x] has been forgotten by Mathematica (like, a part of the code has been deleted, or "Quit kernel" has been applied). Is it possible to extract f[x] from plot, i.e. is there some operation that allows obtaining f[x] by applying some operation with plot?

• If you go plot//InputForm (or FullForm - and you can do it to the image stored in a notebook as well) you’ll get a giant output, but you’ll be able to see the actual code held by Mathematica. Generally, it’s full of line objects of GraphicsComplex which all have numerical data. If you had a hint on what the original function was, you might be able to fit it to the data stored there, but I don’t think you can recover the function perfectly. Commented Dec 10, 2020 at 9:04
• @MassDefect, This way will not give you a function. The graphics of Plot stored in notebook is a postscript-like object, i.e. there are a lot of coordinates of points and curves but there is not an original function behind them Commented Dec 10, 2020 at 10:02
• You can recover the GraphicsComplex (or point data) from the graphics and then fit the data to a function using one of several of the built-in functions. The fitting process may yield the original function. For example, generate 100 points of sin(x), then use FindFormula and include Sine in the list of target functions. I suspect this will return sin(x). Commented Dec 10, 2020 at 12:56
• @Rom38 Right, that’s exactly what I meant. Sorry if I wasn’t clear. All that’s stored in there is raw data as lines and graphics complex objects. Commented Dec 10, 2020 at 19:03

plot = Plot[{x^2 - 1/4 x^3, x Sin[x]}, {x, 0, 10}, PlotRange -> All, PlotLegends -> "Expressions"]

Out={1. x^2. - 0.25 x^3., x Sin[x]}