diff scripts/plot/gnuplot_drawnow.m @ 9478:7e1e90837fef

Avoid the flickering x11 window seen with rapid gnuplot updates.
author Ben Abbott <bpabbott@mac.com>
date Sun, 02 Aug 2009 16:52:12 -0400
parents 5af462716bff
children c60a9e1a0372
line wrap: on
line diff
--- a/scripts/plot/gnuplot_drawnow.m	Fri Jul 31 10:17:44 2009 +0200
+++ b/scripts/plot/gnuplot_drawnow.m	Sun Aug 02 16:52:12 2009 -0400
@@ -268,43 +268,50 @@
       size_str = "";
     endif
 
-    ## Set the gnuplot terminal (type, enhanced?, title, & size).
-    if (! isempty (term))
-      term_str = sprintf ("set terminal %s", term);
-      if (any (strncmpi (term, {"x11", "wxt"}, 3)) && new_stream
-	  && __gnuplot_has_feature__ ("x11_figure_position"))
-        ## The "close" is added to allow the figure position property
-        ## to remain active.
-        term_str = sprintf ("%s close", term_str);
-      endif
-      if (! isempty (enh_str))
-        term_str = sprintf ("%s %s", term_str, enh_str);
-      endif
-      if (! isempty (title_str))
-        term_str = sprintf ("%s %s", term_str, title_str);
+    ## Set the gnuplot terminal (type, enhanced, title, options & size).
+    term_str = sprintf ("set terminal %s", term);
+    if (! isempty (enh_str))
+      term_str = sprintf ("%s %s", term_str, enh_str);
+    endif
+    if (! isempty (title_str))
+      term_str = sprintf ("%s %s", term_str, title_str);
+    endif
+    if (nargin > 3 && ischar (opts_str))
+      ## Options must go last.
+      term_str = sprintf ("%s %s", term_str, opts_str);
+    endif
+    if (! isempty (size_str) && new_stream)
+      ## size_str comes after other options to permit specification of
+      ## the canvas size for terminals cdr/corel.
+      term_str = sprintf ("%s %s", term_str, size_str);
+    endif
+    ## Work around the gnuplot feature of growing the x11 window when
+    ## the mouse and multiplot are set.
+    fputs (plot_stream, "unset multiplot;\n");
+    if (! strcmp (term, "x11")
+        || numel (findall (h, "type", "axes")) > 1
+        || numel (findall (h, "type", "image")) > 0)
+      fprintf (plot_stream, "%s\n", term_str);
+      if (nargin == 5)
+        if (! isempty (file))
+          fprintf (plot_stream, "set output '%s';\n", file);
+        endif
       endif
-      if (nargin > 3 && ischar (opts_str))
-        ## Options must go last.
-        term_str = sprintf ("%s %s", term_str, opts_str);
+      fputs (plot_stream, "set multiplot;\n");
+    elseif (strcmp (term, "x11"))
+      fprintf (plot_stream, "%s\n", term_str);
+      if (nargin == 5)
+        if (! isempty (file))
+          fprintf (plot_stream, "set output '%s';\n", file);
+        endif
       endif
-      if (! isempty (size_str) && new_stream)
-        ## size_str goes last to permit specification of canvas size
-        ## for terminals cdr/corel.
-        term_str = sprintf ("%s %s", term_str, size_str);
-      endif
-      fprintf (plot_stream, "%s\n", term_str);
-    else
-      ## gnuplot will pick up the GNUTERM environment variable itself
-      ## so no need to set the terminal type if not also setting the
-      ## figure title, enhanced mode, or position.
     endif
+  else
+    ## gnuplot will pick up the GNUTERM environment variable itself
+    ## so no need to set the terminal type if not also setting the
+    ## figure title, enhanced mode, or position.
   endif
 
-  if (nargin == 5)
-    if (! isempty (file))
-      fprintf (plot_stream, "set output '%s';\n", file);
-    endif
-  endif
 
 endfunction