MathGroup Archive 1993

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

Search the Archive

Graphics output as input - Final Summation

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Graphics output as input - Final Summation
  • From: <Davin.Potts at math.tamu.edu>
  • Date: Mon, 11 Oct 93 18:02:33 CDT

 
> We are plotting some graphs that take a long time to compute (at least
> on an aging Sun-3).  We want to save the graphics to files, then come
> back and display them all at once.  The first step is easy:
> 
> Display["<filename>.ps", <graphics command>]
> 
> where <graphics command> is something like
> 
> Plot[myslowfunction[x], {x,-1,1}] .
> 
> But how to read the files back in, in a later session?  In the
> Mathematica book, the documentation for Read[] and ReadList[] gives a
> list of allowed "types" of input data, but "Graphics" is not among
> them!  Our solution is somewhat complex, and not exactly obvious from
> the book, so it may be of general interest:
> 
> Show[Graphics[Thread[PostScript[Readlist["<filename>.ps",
> 			String]]]]] .
> 
> =========================== clip here ===================
> 
> ReadGraph[x_] :=
>      Show[Graphics[Thread[PostScript[ReadList[x,String]]]]]
> 
> =========================== clip here ===================
> 
> 				    Davin M. Potts
> 				    Stephen A. Fulling

We appreciate the responses to this original posting.  Here is a
short summary of the responses, accompanied by a general solution to
the problem of saving then redisplaying graphics in Mathematica.

All responses used the same method, more or less, to save graphics
plots to a file.  The responses differed in methods of redisplaying
the graphics when it came to types of front ends and versions of Mma.

M.R. Schaferkotter, Tom Bahder, and Michael Prange all suggested
essentially the same solution.  That was to read the file into Mma
in the most basic way using "!!plotfile" or "<<plotfile".  Bahder's
and Prange's front ends interpreted the file being read in as 
PostScript, and displayed it appropriately.  For Schaferkotter, the
additional step was needed of selecting the cell and using the
Style Inspector Menu to change the cell to Graphics (in Mma 2.0,
with a similar final step needed in Mma 1.2).

Unfortunately, this would not work on our Sun-3.  We are running
a version of Mma without a notebook front end and have no ability
to select cells and change them to Graphics cells.  In addition, 
our front end is apparently not capable of automatically detecting
PostScript files being read in.

Amaro Rica da Silva suggested a modification to our ReadGraph function.
Using Rica da Silva's suggestion, ReadGraph could be defined:
  ReadGraph[x_] := 
     Show[Graphics[PostScript@@ReadList[x,Record]]]
His modification of replacing "Thread" with "@@" changed the function
calling convention, but the two forms are probably interchangable.
His change from "String" to "Record" allows the PostScript routine 
to chew on the entire PS file at once, instead of one line at a time.

This second modification may be the solution to Schaferkotter's 
problem with ReadGraph that it resulted in his getting "blank" 
PostScript cells.  It is perhaps possible that each time a single
string of PostScript was "threaded" through to "PostScript[]",
the Graphics cell was blanked by the front end so that the new 
graphics would be displayed on a blank background.  Thus, the last
PostScript command, possibly to draw a single point, resulted in a
blank cell for Schaferkotter.  The change from String to Record may 
solve this problem in that the entire file will be displayed using
a single execution of "PostScript[]".

Thus Rica da Silva's modifications result in a general routine that
should work on a large variety of Mma front ends.

=========================== clip here ===================

  ReadGraph[x_] := 
       Show[Graphics[PostScript@@ReadList[x,Record]]]

=========================== clip here ===================

 				    Davin M. Potts
				    Stephen A. Fulling






  • Prev by Date: Table Lookup
  • Next by Date: Hold[], Evaluate[] and so forth.
  • Previous by thread: Re: Table Lookup
  • Next by thread: Hold[], Evaluate[] and so forth.