Re: Getting values from a Plot

*To*: mathgroup at smc.vnet.net*Subject*: [mg7483] Re: Getting values from a Plot*From*: Alistair.Windsor at vuw.ac.nz (Alistair.Windsor at vuw.ac.nz)*Date*: Thu, 5 Jun 1997 01:36:41 -0400 (EDT)*Organization*: Victoria University of Wellington, New Zealand*Sender*: owner-wri-mathgroup at wolfram.com

In article <5mloc9$npu at smc.vnet.net>, Joe Shamblin <wjs at cs.duke.edu.nospam> wrote: > llosas <pere.llosas at imt.dmt.epfl.ch> writes: > > > Does anyone know how to get a list with the values calculated to display > > a graph with the Plot function? {{x0,y0},{x1,y1},...{xn,yn}} > > You can use something like this, although you have to parse the data a > bit. There might be a way to get it to automatically output this data > in a nice form, but I am not aware of one. > > In[4]:= Plot[Sin[x], {x, -10,10}] > Out[4]= -Graphics- > > In[5]:= InputForm[FullGraphics[%4]] > > Out[5]//InputForm= > Graphics[{{{Line[{{-9.999999166666666, 0.5440204116629069}, The best (IMHO) answer has already been provided by Hans Steffani which was Plot[Sin[x],{x,-10,10}][[1,1,1,1]]. I does appear at first glance to be mysterious. Your use of InputForm is along the right track. I find it easier to use TreeForm for working out how to extract parts of an object. Typing TreeForm[Plot[Sin[x],{x,-10,10}]] (suppress the plot with DisplayFunction if you like) gives you a tree form of the expression from which it is easy to see the list of points plot uses is part [[1,1,1,1]]. This approach lets you work out the position of other things you might want to extract, like the options used Plot[Sin[x],{x,-10,10}][[2]]. The purpose of this is not to give the solution but point out how the solution could have been obtained. The use of TreeForm is entirely optional but does make it easier to work out what is one what level and at what position. Another point here. Plot uses some clever routines to determine what the best points to plot are. When writing your own graphics routines it is often worthwhile using Plot with the plot suppressed (DisplayFunction->Identity) to work out the "best" points. For those interested in these sort of tricks there are two worthwhile items on MathSource entitled Graphics Programming and Non-Trivial Graphics Programming. Graphics Programming was written by graphics guru Tom Wickham-Jones. His package ExtendGraphics is definitely a must both for the functionality it provides and the ideas the packages can give you. -- Alistair Windsor Mathematics Graduate Student Victoria University of Wellington New Zealand