9

The problem with octave(matlab). In the program I have loop where I plot data. In the end of each loop I save plots to disc. During this process octave draw each plot. It slows down the process. I need only plots to be saved on disc. If I could not display them,but just save, it would considerably accelerate the process. Is there way to draw plot to handler without displaying it? to draw I use scatter function.

ashim
  • 24,380
  • 29
  • 72
  • 96
  • possible duplicate of [In MATLAB, how do I plot to an image and save the result without displaying it?](http://stackoverflow.com/questions/963674/in-matlab-how-do-i-plot-to-an-image-and-save-the-result-without-displaying-it) – yuk Jan 04 '12 at 15:32
  • 4
    This is not really a duplicate, since this is about OCTAVE not MATLAB. – Ramiro Jun 19 '14 at 15:23

3 Answers3

8

This is not tested with matlab, and potentially only limited to octave.

Using f = figure('visible','off') will not work out of the box.

You need to select a proper graphics toolkit:

available_graphics_toolkits 
ans = 
{
  [1,1] = fltk
  [1,2] = gnuplot
}

The default is fltk which cannot write to file without displaying the plot. However, if you select gnuplot it will be able to write to file without displaying it first:

graphics_toolkit gnuplot

f = figure('visible','off')
plot(...)
axis(...)
filename=sprintf('output/%05d.png',t);                                                                          
print(filename); 

It is not particularly fast, but it doesn't use screen buffers or captures the mouse, which happens if the plot needs to be visible.

Anne van Rossum
  • 3,091
  • 1
  • 35
  • 39
5

As answered in this question, I would do:

f = figure('visible','off')
Community
  • 1
  • 1
Oli
  • 15,935
  • 7
  • 50
  • 66
  • 1
    If the question is exact duplicate it's better to close it with the link to original question, or add the link in comments if you don't have enough points. – yuk Jan 04 '12 at 15:31
  • 2
    when I do this with octave, any try to print the figure to a file fails. When I create the figure with visible on I can print it just fine. – kaefert Jan 15 '15 at 13:32
2

Offscreen rendering is supported on GNU/Linux since GNU Octave 4.0 using OSMesa. So today there are basically two ways to get figure ("visible", "off");... print (...)working:

  1. If you not have a proprietary OpenGL driver but a MESA based driver like radeon, nouveau and so on (basically all free (as in freedom) drivers are based on Mesa) you can use OpenGL based toolkits (qt, fltk) and Octave will use OSMesa for printing.
  2. Using gnuplot: graphics_toolkit gnuplot as said before
Andy
  • 7,931
  • 4
  • 25
  • 45