Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot from octave to a pdf without X11

I want to create pdf or png plots from octave on an ubuntu system where I just have a command line, no X11, no windows. I want to do something like this:

plot(x, y);
print -dpng myplot.png

But plot gives me this warning:

warning: X11 DISPLAY environment variable not set 

And both commands just give me a character graphic rendition on the console. Do I need to set GNUTERM to something?

like image 902
Greg Clinton Avatar asked Jan 24 '26 21:01

Greg Clinton


1 Answers

This is a really old question but it was the top result for me. Relevant for today's cloud services, here are ways to approach the problem:

figure ("visible", "off")
plot (1:10)
print output.png

If you don't want to work just with files, X11 can be forwarded for remote viewing. Run Octave remotely and display locally via x11 assumes the X11 libraries are installed and ready to go...so just add -X to ssh:

ssh -X remoteserver

To get X11 there in the first place, these articles:

  • X11 forwarding from amazon ec2 ami
  • AWS Developer Forums: X11 forwarding...DISPLAY not set...

suggest:

  • Edit /etc/ssh/sshd_config and set
    • X11Forwarding yes
    • CentOS might need these instead:
      • ForwardX11 yes
      • ForwardX11Trusted yes
  • $ sudo yum groupinstall "X Window System"
    • or install the single packages you want
  • $ export DISPLAY=localhost:10.0
    • This variable is only missing if xauth isn't installed
  • $ sudo yum install xauth
    • Not installed by default

and just in case you indeed run into a GNUTERM error: Octave Plotting Error suggests compiling gnuplot with X11 support and setting the environment before plotting anything:

$ (whatever installs) gnuplot --with-x11

Then in Octave:
#setenv("GNUTERM", "qt")
setenv("GNUTERM","X11")
plot(x,y)
like image 120
ǝɲǝɲbρɯͽ Avatar answered Jan 27 '26 14:01

ǝɲǝɲbρɯͽ