Re: Mathlink & Graphics....
- To: mathgroup at smc.vnet.net
- Subject: [mg2228] Re: Mathlink & Graphics....
- From: wagner at goober.cs.colorado.edu (Dave Wagner)
- Date: Tue, 17 Oct 1995 02:34:56 -0400
- Organization: University of Colorado, Boulder
In article <45d1sc$63m at ralph.vnet.net>, The GodFather <gandalf at dogbert.ugcs.caltech.edu> wrote: > > Unix Platform.... > > I've been trying to do this for a bit of time.... > > Basically, I would like from a C-code, to generate > a list of numbers {{1,2},{2,1}} and plot their positions > using mathematica's handy plotting routines.... > > If someone could post a way to simply execute a > Plot[x^2,{x,-2,2}], and either have mathematica display > it (in X), or return PostScript to the link stream or > to an output file I would be extremely grateful.... > > An example of the type of thing I'm trying to do.... > > from within C-code: > > MLPutFunction(link,"Extend",1); > PutString(link,"Plot[x^2,{x,-2,2}); > > If there was some way of setting the DisplayFunction > so mathematica would then just plot this thing out 'twould > be beautiful. If there was some way I could get it to > output the plot to a postscript file, I would be joyous. > If there was any way I could get useable output, basically > I would be dancing around for weeks.... > > with much appreciation, > > -John Joseph You can redirect the PostScript output of a plotting command by overriding DisplayFunction. The default setting for DisplayFunction is $DisplayFunction, which is In[33]:= $DisplayFunction Out[33]= Display[$Display,#1]& This function is applied to the Graphics object that is generated by the plot command. Display is a built-in function that sends graphics to a particular place: In[34]:= ?Display Display[channel, graphics] writes graphics or sound to the specified output channel. The default value for $Display is: In[35]:= $Display Out[35]= stdout so, you can accomplish what you want to do by (a) opening a stream to a file in Mathematica, (b) one of the following: - set $Display to that stream - set $DisplayFunction to Display[stream, #]& - use the option DisplayFunction:>Display[stream, #]& in your plotting command. This is probably the best option since you'll undoubtedly want to use a different stream for each plot. Note that the contents of the file with be Mathematica-ese PostScript, which isn't interpretable by most PostScript interpreters, I don't think. There's a UNIX program that can do it that's distributed on MathSource, I believe. Let me know if this makes you dance... Dave Wagner Principia Consulting (303) 786-8371 dbwagner at princon.com http://www.princon.com/princon