I'm running mathematica in command line mode, but I need to view a graph/image, so I'd like to open an image with an X11 window to inspect an image:

enter image description here

Is there an easy way or built-in command to to this?


This differs from the post Mr. Wizard references, because the terminal is running remotely in ssh:

enter image description here

This is how I do it in the terminal usually:

enter image description here

but doesn't work from within mathematica:

enter image description here

  • 1
    $\begingroup$ What does $DisplayFunction return on the command line? $\endgroup$ Jul 26, 2016 at 16:44
  • $\begingroup$ One easy way to do it is to export the file, then have the system open it. i.sstatic.net/Okn2s.png $\endgroup$
    – Jason B.
    Jul 26, 2016 at 16:50
  • $\begingroup$ Would you please clarify how this differs from (48239)? $\endgroup$
    – Mr.Wizard
    Jul 26, 2016 at 17:24
  • $\begingroup$ $DisplayFunction is Identity $\endgroup$
    – M.R.
    Jul 26, 2016 at 17:38
  • 1
    $\begingroup$ Then you can modify it so that graphical output is redirected to e.g. stdout. What OS are you on? $\endgroup$ Jul 26, 2016 at 17:40

3 Answers 3


Might be relevant, but this is something I use that uses StartProcess and ProcessConnection.

xShow[expr_] := Module[{pr = StartProcess[{"display", "png:fd:0"}]},
  WriteLine[ProcessConnection[pr, "StandardInput"], 
    ExportString[expr, "PNG"]];



results in:


This pipes the output to the program display.

I wanted to use this as the $DisplayFunction, but that doesn't cover things like GeoGraphics or other functions that don't use $DisplayFunction, and Plot does some strange doubling (you first get a blank plot and then a plot with the function).

A clever use of $Post could be used rather than my Postfix use.


As long you've set X11 forwarding correctly JavaGraphics should work just fine. I.e, ssh -Y remote followed by


in the remote kernel.


I always use Mathematica from the command line and have usually done display by setting the file init.m in Library/Mathematica/...Kernel/ to the script below. This works on a Mac; it writes the graphics to a pdf file, then displays it.

Unfortunately, in Math 11 some of the graphics displays no longer use $DisplayFunction (e.g. ListPlot, Show, ...) and I haven't found a good workaround yet. But the code below works well for Plot, Plot3D, etc.

(*-----------Graphics for command line Mathematica ----------------*)
(*  Install this file in Math../Configuration/Kernel/init.m *)
(*  It may be necessary to create this directory *)
(*  Writes images as PDF files to /tmp/math.xx; then uses Preview to show them *)

Begin["System`Private`"]  ;
MaxImages = 100;
ImageNumber = 0;
Unprotect[ $DisplayFunction]; Clear[ $DisplayFunction]; $Display = {};
$DisplayFunction := Block[{fid,str},
str=Export[fid, #,"pdf"];
Run["open -a Preview "<>fid<>" &"];
ImageNumber = Mod[ImageNumber+1,MaxImages];

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.