MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Graphics and DisplayFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98275] Re: Graphics and DisplayFunction
  • From: mark mcclure <mcmcclur at unca.edu>
  • Date: Sun, 5 Apr 2009 06:33:24 -0400 (EDT)
  • References: <gqsn9m$3tr$1@smc.vnet.net> <gr21l6$lq8$1@smc.vnet.net>

On Apr 3, 5:11 am, David Bailey <d... at removedbailey.co.uk> wrote:
> I would forget about the DisplayFunction option - it is more or
> less obsolete.

If DisplayFunction -> f is used as an option to a Plot function
or Show, then f is applied to the result.  Since the default
value of DisplayFunction is $DisplayFunction, this makes
$DisplayFunction something like $Post for graphical commands.
This can be quite handy.  Here are three example settings for
$DisplayFunction.

 * Create a tooltip when hovering over a graph:
   $DisplayFunction = Tooltip[#, "On graph!"] &;

 * Show graph and also auto-export to a file:
   cnt = 0;
   $DisplayFunction = (
     Export["pic" <> ToString[++cnt] <> ".png",#]; #
   )&;

 * Send graphics to another program:
   df[g_] := Module[
     {strm},
     strm = OpenWrite["!open -f -a /Applications/Preview.app"];
     WriteString[strm, ExportString[g, "EPS"]];
     Close[strm]
   ];
   $DisplayFunction = df;

After defining $DisplayFunction by entering any of these
commands, simply enter a graphical command, like
Plot[x^2, {x,-2,2}], to see it in action.  The last
example is set up to pipe the output to Preview.app on the
Mac, but I suppose that something similar would work on the
PC.  This last one is most interesting if you're running a
text based interface, like the Mac Terminal.  To get it to
work in that context you need to install a front end as well
by first entering:
Developer`InstallFrontEnd[];
I actually do this frequently when manipulating Mathematica
from other programs.

So, have fun with DisplayFunction,
Mark McClure


  • Prev by Date: Re: passing an array variable as a file name string to FindList
  • Next by Date: Re: Can't figure out how to export Mathematica into Word
  • Previous by thread: Re: Graphics and DisplayFunction
  • Next by thread: Re: Graphics and DisplayFunction