1

I am new to python and trying to explore graphs, could you please help me understand if I can plot graphs on the console using matplotlib on a linux system that has no XSERVER running?

Thanks.

Mithuna
  • 13
  • 3

1 Answers1

1

You can use matplotlib with no X server by setting the backend to Agg, PS, PDF or SVG, Cairo or GDK (depending on what kind of file you wish to create). You can set the backend in your matplotlibrc file, which, depending on your installation, may be in a directory such as ~/ or ~/.matplotlib or ~/.config/matplotlib/.

Alternatively, you can set the backend in the script itself. Be sure to set the backend first, before importing other modules such as pyplot:

import matplotlib
matplotlib.use("Agg")

See this SO question for examples.

Community
  • 1
  • 1
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Is there no other way to display directly on the console while running the script than saving to file? I am not sure how can i display this file without graphics support on the box. Thanks – Mithuna Sep 06 '14 at 17:05
  • I don't have much experience with this, but there are console image viewers such as [feh](http://ubuntuguide.net/feh-lightweight-command-line-command-console-image-viewer-for-linux) or [fbi](http://manpages.ubuntu.com/manpages/gutsy/man1/fbi.1.html). So you could save the image to a file using matplotlib, and then use subprocess to call feh or fbi to display the image. [Pygame](http://pygame.org/wiki/about) can also display to the linux frame buffer. – unutbu Sep 06 '14 at 18:10