Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>f = Sin[t]; plot = Plot[f, {t, 0, 10}] </code></pre> <p>One way to extract points is as follows:</p> <pre><code>points = Cases[ Cases[InputForm[plot], Line[___], Infinity], {_?NumericQ, _?NumericQ}, Infinity]; </code></pre> <p>ListPlot to 'take a look'</p> <pre><code>ListPlot[points] </code></pre> <p>giving the following:</p> <p><img src="https://i.stack.imgur.com/E2dMx.gif" alt="enter image description here"></p> <p><strong>EDIT</strong> Brett Champion has pointed out that <code>InputForm</code> is superfluous. </p> <pre><code>ListPlot@Cases[ Cases[plot, Line[___], Infinity], {_?NumericQ, _?NumericQ}, Infinity] </code></pre> <p>will work. </p> <p>It is also possible to paste in the plot graphic, and this is sometimes useful. If,say, I create a ListPlot of external data and then mislay the data file (so that I only have access to the generated graphic), I may regenerate the data by selecting the graphic cell bracket,copy and paste:</p> <pre><code>ListPlot@Transpose[{Range[10], 4 Range[10]}] points = Cases[ Cases[** Paste_Grphic _Here **, Point[___], Infinity], {_?NumericQ, _?NumericQ}, Infinity] </code></pre> <p><strong>Edit 2</strong>.</p> <p>I should also have cross-referenced and acknowledged <a href="https://stackoverflow.com/questions/4245946/vertexcoordinate-rules-and-vertexlist-from-graphplot-graphic/4250069#4250069">this</a> very nice answer by Yaroslav Bulatov. </p> <p><strong>Edit 3</strong></p> <p>Brett Champion has not only pointed out that <code>FullForm</code> is superfluous, but that in cases where a <code>GraphicsComplex</code> is generated, applying <code>Normal</code> will convert the complex into primitives. This can be very useful. </p> <p>For example:</p> <pre><code>lp = ListPlot[Transpose[{Range[10], Range[10]}], Filling -&gt; Bottom]; Cases[ Cases[Normal@lp, Point[___], Infinity], {_?NumericQ, _?NumericQ}, Infinity] </code></pre> <p>gives (correctly)</p> <blockquote> <p>{{1., 1.}, {2., 2.}, {3., 3.}, {4., 4.}, {5., 5.}, {6., 6.}, {7., 7.}, {8., 8.}, {9., 9.}, {10., 10.}}</p> </blockquote> <p>Thanks to Brett Champion.</p> <p>Finally, a neater way of using the general approach given in this answer, which I found <a href="http://mathgis.blogspot.com/2008/08/how-to-extract-points-from-plot.html" rel="nofollow noreferrer">here</a></p> <p>The OP problem, in terms of a ListPlot, may be obtained as follows:</p> <pre><code>ListPlot@Cases[g, x_Line :&gt; First@x, Infinity] </code></pre> <p><strong>Edit 4</strong></p> <p>Even simpler </p> <pre><code>ListPlot@Cases[plot, Line[{x__}] -&gt; x, Infinity] </code></pre> <p>or</p> <pre><code>ListPlot@Cases[** Paste_Grphic _Here **, Line[{x__}] -&gt; x, Infinity] </code></pre> <p>or</p> <pre><code>ListPlot@plot[[1, 1, 3, 2, 1]] </code></pre> <p>This evaluates to <code>True</code></p> <pre><code>plot[[1, 1, 3, 2, 1]] == Cases[plot, Line[{x__}] -&gt; x, Infinity] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload