
Re: Getting the plotted data from a graph
Posted:
Jun 16, 2013 5:10 AM


Lily,
You should be aware that the points that you obtain are dependent upon the details of the plotting algorithm. Here I have used Options simply to limit the number of points.
g1 = Plot[Sin[x], {x, Pi, Pi}, PlotPoints > 20, MaxRecursion > 1, Frame > True, FrameLabel > {"x", "y"}, ImageSize > 2.6*72]
If you keep clicking on the plotted line Mathematica will display the points it used to draw the curve. However, that does not get their coordinates. You could extract their coordinates using:
First@Cases[First[g1], ln_Line :> First[ln], Infinity]
{{3.14159, 3.30694*10^7}, {2.98256, 0.158362}, {2.82353, \ 0.312727}, {2.65112, 0.471041}, {2.47871, 0.615389}, {2.31773, \ 0.733775}, {2.15675, 0.833186}, {1.99892, 0.909745}, {1.8411, \ 0.963691}, {1.6699, 0.995094}, {1.49869, 0.997402}, {1.33892, \ 0.973236}, {1.17914, 0.924278}, {1.00599, 0.84469}, {0.832833, \ 0.73984}, {0.662837, 0.615356}, {0.492841, 0.473131}, \ {0.334271, 0.32808}, {0.1757, 0.174797}, {0.168195, 0.167403}, {0.489239, 0.469954}, {0.646604, 0.602479}, {0.803968, 0.720115}, {0.974709, 0.827539}, {1.14545, 0.910896}, {1.30477, 0.964822}, {1.46408, 0.994311}, {1.63678, 0.997824}, {1.80947, 0.971653}, {1.979, 0.917834}, {2.14854, 0.837698}, {2.30665, 0.741259}, {2.46476, 0.626329}, {2.63624, 0.484112}, {2.80773, 0.327694}, {2.97466, 0.166157}, {3.14159, 3.30694*10^7}}
The Presentations Application has a command that makes this a bit more convenient.
<< Presentations `
Extract2DLinePoints[g1]
So you could draw the curve and then plot the points used on top of it.
Draw2D[ {g1 = Draw[Sin[x], {x, Pi, Pi}, PlotPoints > 20, MaxRecursion > 1], PointSize[0.015], Point /@ Extract2DLinePoints[g1]}, Frame > True, FrameLabel > {"x", "y"}]
David Park djmpark@comcast.net http://home.comcast.net/~djmpark/index.html
From: Lily T. [mailto:econactually@gmail.com]
Dear All,
My question is regarding the plotted data points in a graph. Assume you draw a graph of sinx as:
g1 = Plot[Sin[x], {x, Pi, Pi}, Frame > True, FrameLabel > {"x", "y"}, ImageSize > 2.6*72 ]
then how can I get all of the data points of this graph by using mathematica?
This is really important for me and I couldn't find the answer anywhere online!
Thank you for your help in advance!
Best, Lily

