Being a long time unix shell person, I prefer Mathematica's command line interface, over the notebook. (command history, etc...)

It just learned that on OS X, the cli is available as MathKernel.

What I'm wondering now is, is it possible to open graphics (and/or animations, sounds, etc) result, from within the command line?

In[16]:= Plot[Sin[x], {x, -Pi, Pi}]

Out[16]= -Graphics-

I would like to be able to view output #16.

  • $\begingroup$ You need to load <<JavaGraphics` . See also my answer here (that question and title should probably rewritten) $\endgroup$
    – rm -rf
    May 21, 2014 at 4:20
  • $\begingroup$ @rm-rf Strangely, when using <<Terminal` , I get garbage output on OS X. $\endgroup$
    – Szabolcs
    May 21, 2014 at 14:03
  • $\begingroup$ @Szabolcs Terminal is for ASCII graphics and it has worked for me $\endgroup$
    – rm -rf
    May 21, 2014 at 14:06
  • $\begingroup$ @rm-rf I thought it has worked for me too, but I'm getting this now. Have you tried on Mavericks? $\endgroup$
    – Szabolcs
    May 21, 2014 at 14:14
  • $\begingroup$ @Szabolcs You're right, that's what I get too on Mavericks. Nothing comes to mind immediately as to what could be wrong... $\endgroup$
    – rm -rf
    May 21, 2014 at 15:37

2 Answers 2


You must use a FrontEnd to generate actual images, but you don't have to use the notebook interface. You can actually do all of this from a standalone kernel. (You must be logged in to a system that allows you to launch GUI applications, though.)

For example:

In[5]:= g=Plot[Sin[x],{x,-Pi,Pi}];                                              

In[6]:= Export["testplot.png",g]                                                

Out[6]= testplot.png

In[7]:= UsingFrontEnd[SystemOpen["testplot.png"]]

You first create the object you want to see (in this case expression g). Then you pass it to Export. Export will launch the FrontEnd as a service to render the expression, and then the Kernel will convert it to the format specified in Export and save it to disk. You can then view it using SystemOpen. This technique will also work with animations (you will need to use an export format like QuickTime).

  • $\begingroup$ Thanks to everyone who answered my question. This, and the info about <<JavaGraphics` and <<Terminal` are exactly what I am looking for. (fwiw, I also get noise with terminal graphics under Mavericks, but I feel like that can probably be sorted out.) $\endgroup$
    – billc
    May 21, 2014 at 17:00
  • $\begingroup$ @ChristopherCole Just curious: why does the kernel have to launch the FrontEnd to export? (I assume that's just images?) It seems odd that if we are writing data to a file that the kernel couldn't do that by itself. $\endgroup$
    – mfvonh
    May 21, 2014 at 17:32
  • $\begingroup$ Ultimately, you need something to render Graphics[...directives, primitives, and options...]. The FrontEnd isn't the only program that knows how to do this; JavaGraphics` in the Kernel can render those primitives and directives it understands. However, since V6, Graphics, like formatted text and equations, are really box expressions and therefore subject to styles and style inheritance. The FrontEnd knows how to resolve these styles, so asking the FrontEnd to perform the render means that the exported graphic will have nearly the same appearance as in a Notebook. $\endgroup$ May 21, 2014 at 18:42

If you are using a windowing system, the following before evaluating a graphic should work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.