Study of Mathematica Patterns(1)

Question : How to Get data in Plot =>Use patterns to get coordinate values

Peek the whole format with InputForm.Use Short to simplify formatting.According to these relations, complete a function, test OK!!

Share the code with you.

Plot[Sin[x], {x, 0, 2 \[Pi]}]
Plot[Sin[x], {x, 0, 2 \[Pi]}, MaxRecursion -> 1, 
  PlotPoints -> 20] // InputForm
Plot[Sin[x], {x, 0, 2 \[Pi]}, MaxRecursion -> 1, PlotPoints -> 20] // 
  InputForm // Short
myFunction[f__] :=
 Cases[{f},
   Graphics[ {{{___, Annotation[{___, 
                Line[www__]},  ___]}}, ___},  ___]
    -> www][[1]]
Plot[Sin[x], {x, 0, 2 \[Pi]}, MaxRecursion -> 1, 
  PlotPoints -> 20] // myFunction

Of course, the easiest way to read the coordinates of the plot is to replace the Head

發表留言