Can't plot with gnuplot on my Mac

I am trying to plot with gnuplot on my Mac (OS X 10.8.5). I have installed X11 and XQuartz 2.7.4 and after that I installed gnuplot, but unfortunately gnuplot couldn't plot.

Simple plots like the following fail to render and have no error message to help understand what is amiss:

 [1/10/13 $gnuplot >plot sin(x)

Solution 1:

The same thing happened to me, but then I ran

brew uninstall gnuplot; brew install gnuplot --with-x11

and installed XQuartz. Now gnuplot supports the x11 terminal:

You can also save the output to a file and use qlmanage -p:

gnuplot -e 'set term png; set output "/tmp/plot.png"; plot sin(x)'; qlmanage -p /tmp/plot.png

qlmanage -p shows a sandboxing error in 10.9 and prints some unnecessary text to STDOUT, so I use a function like ql() { qlmanage -p "$@"&>/dev/null; } in shells.

A third option is to use set term dumb for plain text output.

Solution 2:

In OS X Yosemite 10.10.2 and El Capitan 10.11.2, the Gnuplot does not package with XQuartz. Answer in bibstha's comment. Much more robust window manager is in qt and it works

 brew uninstall gnuplot
 brew install gnuplot --with-qt

Note that using --qt is deprecated now.

Solution 3:

Are you running this from a Terminal window, or an X11 window? The terminal will launch X11 separately to show the plot, so it may not be immediate (or visible). Does X11 get launched at all when you type your plot command?

If you try it in an X11 window, the result should be more immediate.

Also, if you used macports to install it originally, I would recommend using homebrew instead:

brew install gnuplot

EDIT: To check where the output is going, you could direct your results to a file:

set terminal png
set output 'testimage.png'
plot sin(x)
exit

Then see if a file called testimage.png contains your plot. You could also try specifying the terminal with:

set terminal x11

Solution 4:

In Yosemite, Initially, I had quartz and gunplot 5.0.0 installed. However, I could not load my x11 window (everything else was file-X11 was somehow unknown). Here is a workaround that 'worked for me'.

Go to the gunplot source folder

make clean; 
make uninstall

then in the "configure" file under the following lines

# Standard set of common directories for X headers.

# Check X11 before X11Rn because it is often a symlink to the current release.

---added the location of my X11 files also  
/opt/X11/include

now run

./configure
make
sudo make install

worked perfectly for me as you see below

G N U P L O T
Version 5.0 patchlevel 0    last modified 2015-01-01 

Copyright (C) 1986-1993, 1998, 2004, 2007-2015
Thomas Williams, Colin Kelley and many others

gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help FAQ"
immediate help:   type "help"  (plot window: hit 'h')

Terminal type set to 'x11'.