Mathematica: How to obtain data points plotted by plot command?

后端 未结 7 1870
[愿得一人]
[愿得一人] 2021-01-30 15:34

When plotting a function using Plot, I would like to obtain the set of data points plotted by the Plot command.

For instance, how can I obtain the list of points {t,f} P

7条回答
  •  花落未央
    2021-01-30 15:41

    In addition to the methods mentioned in Leonid's answer and my follow-up comment, to track plotting progress of slow functions in real time to see what's happening you could do the following (using the example of this recent question):

    (* CPU intensive function *)
    LogNormalStableCDF[{alpha_, beta_, gamma_, sigma_, delta_}, x_] :=
     Block[{u},
      NExpectation[
       CDF[StableDistribution[alpha, beta, gamma, sigma], (x - delta)/u], 
       u \[Distributed] LogNormalDistribution[Log[gamma], sigma]]]
    
    (* real time tracking of plot process *)
    res = {};
    ListLinePlot[res // Sort, Mesh -> All] // Dynamic
    
    Plot[(AppendTo[res, {x, #}]; #) &@
      LogNormalStableCDF[{1.5, 1, 1, 0.5, 1}, x], {x, -4, 6}, 
     PlotRange -> All, PlotPoints -> 10, MaxRecursion -> 4]
    

    enter image description here

    enter image description here

    enter image description here

    etc.

提交回复
热议问题