You run gnuplot on a remote machine over SSH, or on a server with no desktop, and the interactive window never appears. Instead you get something like:
gnuplot: unable to open display ''
gnuplot: X11 aborted.
Nothing is wrong with your script — gnuplot is trying to open an interactive window on a display that does not exist in this session.
What this message means
The interactive terminals (x11, and the window created by wxt or qt on Linux) draw through the X Window System, which needs a DISPLAY variable pointing at a reachable X server. Over a plain SSH connection, and on headless servers and containers, there is no X server at the other end, so the terminal fails to initialise and gnuplot aborts that output device.
Causes, most likely first
- SSH without X forwarding. You connected with plain
ssh, so no display is forwarded back to your machine. - No graphical environment at all. Servers, containers, WSL setups without a GUI layer, and cron jobs have no X server to open.
- The default terminal is interactive. Sessions that start on x11/wxt/qt hit this on the first
plot, even if you only ever wanted a file.
Fixes, step by step
1. If you really want the interactive window: forward X
Reconnect with forwarding enabled, and make sure an X server is running on your local machine (built into Linux desktops; on macOS use XQuartz; on Windows use an X server such as VcXsrv):
ssh -X user@server # or ssh -Y for trusted hosts
echo $DISPLAY # should print something like localhost:10.0
gnuplot -persist -e 'plot sin(x)'
If $DISPLAY is empty after connecting with -X, the server may have X forwarding disabled in its SSH configuration — that is a server-side setting, not a gnuplot problem.
2. If you just want the plot: write a file instead
The cairo file terminals need no display at all and are the right default for scripts, servers and batch jobs:
set terminal pngcairo size 1000,700 enhanced
set output "plot.png"
plot sin(x) with lines title "sin(x)"
set output
For a document-quality vector file, swap the first two lines for set terminal pdfcairo and a .pdf output name. Our comparison of the pngcairo and pdfcairo terminals explains when each one wins.
3. Prefer wxt or qt where they are available
On a desktop Linux session, set terminal qt or set terminal wxt avoids the X11 path entirely on many builds and gives a nicer interactive window. They still need a real graphical session, though — they do not fix a headless server, where option 2 is the answer.
A minimal script that works anywhere
reset
set terminal pngcairo size 800,600
set output "headless.png"
set title "Works with no display at all"
plot exp(-x**2) with lines linewidth 2
set output
print "Wrote headless.png"
Run it with gnuplot script.gp on the most bare-bones machine you have: because no interactive terminal is ever requested, it succeeds with no X server, no SSH forwarding and no desktop. If the same script works this way but fails in your editing setup, the problem is the session’s display, not the script.
Still stuck?
The official documentation at gnuplot.info includes the full command reference, and the gnuplot-info mailing list linked there is the best place to ask when a script misbehaves in a way this page does not cover — include the exact error message and a small sample of your data when you post.
