MathGroup Archive 2010

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

Search the Archive

Error when attempting to save Graphic to file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109832] Error when attempting to save Graphic to file
  • From: "J. McKenzie Alexander" <jalex at lse.ac.uk>
  • Date: Wed, 19 May 2010 07:15:32 -0400 (EDT)

Hello,

I'm attempting to write a function which, when evaluated, will prompt 
the user for a file name and then - if the dialog isn't cancelled - save 
a specified graphic to the file. My first attempt is as follows (please 
note that the variables 'linesToDraw' and 'pointsToDraw' are defined 
elsewhere by another routine, as are 'a', 'b', and 'c'):

saveGraphicFile[] :=
 Module[{filename},
  filename = SystemDialogInput["FileSave"];
  If[filename != $Canceled,
   Export[filename,
    Graphics[
     {LightGray, EdgeForm[Thickness[0.003]], Polygon[{a, b, c}], Black,
      linesToDraw, {PointSize[0.015], Black, pointsToDraw,
       PointSize[0.01], White, pointsToDraw},
      Text[Style[s1, Medium], a, {-1, 1.3}],
      Text[Style[s2, Medium], b, {0, -1}],
      Text[Style[s3, Medium], c, {1, 1.3}]
      }, ImageSize -> 450, AspectRatio -> Automatic]
    ]
   ]
  ]

When I evaluate this in Mathematica 7.0.1, I get a bunch of errors that 
don't make any sense:

	LightGray is not a Graphics primitive or directive.
	Coordinate a should be a pair of numbers, or a Scaled or Offset form.
	Black is not a Graphics primitive or directive.
	linesToDraw is not a Graphics primitive or directive.
	Black is not a Graphics primitive or directive.
	pointsToDraw is not a Graphics primitive or directive.
	White is not a Graphics primitive or directive.
	pointsToDraw is not a Graphics primitive or directive.
	LightGray is not a Graphics primitive or directive.
	Coordinate a should be a pair of numbers, or a Scaled or Offset form.
	Black is not a Graphics primitive or directive.
	linesToDraw is not a Graphics primitive or directive.
	Black is not a Graphics primitive or directive.
	pointsToDraw is not a Graphics primitive or directive.
	White is not a Graphics primitive or directive.
	pointsToDraw is not a Graphics primitive or directive.

However, if I evaluate the following in a notebook, everything works just fine and I get foo.pdf as a PDF file containing the graphic.

Export["~/tmp/foo.pdf",
 Graphics[
  {LightGray, EdgeForm[Thickness[0.003]], Polygon[{a, b, c}], Black,
   linesToDraw, {PointSize[0.015], Black, pointsToDraw,
    PointSize[0.01], White, pointsToDraw},
   Text[Style[s1, Medium], a, {-1, 1.3}],
   Text[Style[s2, Medium], b, {0, -1}],
   Text[Style[s3, Medium], c, {1, 1.3}]
   }, ImageSize -> 450, AspectRatio -> Automatic]
 ]

In case anyone is interested, this is part of an interactive 3-strategy replicator dynamic model where the user can click on the simplex to plot the evolutionary trajectory which starts at that point. The notebook can be downloaded from

	http://evolve.lse.ac.uk/~jalex/files/math/repl-dynamics.nb

Any suggestions would be greatly appreciated.

Cheers,

Jason

--
Dr J. McKenzie Alexander
Department of Philosophy, Logic and Scientific Method
London School of Economics and Political Science
Houghton Street, London WC2A 2AE





  • Prev by Date: Re: Latex, Mathematica, and journals
  • Next by Date: Re: Equals, Less, Greater, etc; Confused by this simple output.
  • Previous by thread: Re: ProgressIndicator inside DynamicModule
  • Next by thread: Basic histogram