help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnuplot/eps/mono


From: John W. Eaton
Subject: gnuplot/eps/mono
Date: Thu, 06 Dec 2007 17:05:11 -0500

On  6-Dec-2007, A. Scottedward Hodel wrote:

| There's been some discussion on the list about gnuplot generating  
| color eps/epslatex plots when mono is requested.  I used the -debug  
| option in the print script and found that if I removed the text
|       linecolor rgb "#0000ff"
| from the second set style line command then I get a black-and-white  
| plot, whereas the rgb command seems to set gnuplot back to color  
| plotting if it's left t here.
| 
| I can't say whether that's a bug in gnuplot or not.

It seems like a bug to me if you specify "monochrome" and the terminal
driver doesn't ignore color specifications.  Otherwise, what use is
the "monochrome" option?  But I guess that is not the interpretation
of the author of the gnuplot postscript terminal driver:

 The option `color` enables color, while `monochrome` prefers black and white
 drawing elements. Further, `monochrome` uses gray `palette` but it does not
 change color of objects specified with an explicit `colorspec`.

(text taken from the gnuplot help for "set term postscript").

| If routine  
| __go_draw_axes__.m it can be informed of the "mono" option so that it  
| can omit the linecolor command, that should fix at least this part of  
| the problem.

Is the following patch sufficient, or is there more to it than this?

jwe


2007-12-06  John W. Eaton  <address@hidden>

        * plot/print.m: Pass mono to drawnow.
        * plot/drawnow.m: New arg, mono.  Pass it to __go_draw_figure__.
        * plot/__go_draw_figure__.m: New arg, mono.  Pass it to __go_draw_axes.
        * plot/__go_draw_axes__.m: New arg, mono.  If mono is true,
        disable color specifications.


Index: scripts/plot/__go_draw_axes__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__go_draw_axes__.m,v
retrieving revision 1.85
diff -u -u -r1.85 __go_draw_axes__.m
--- scripts/plot/__go_draw_axes__.m     5 Dec 2007 01:18:41 -0000       1.85
+++ scripts/plot/__go_draw_axes__.m     6 Dec 2007 22:02:33 -0000
@@ -20,9 +20,9 @@
 
 ## Author: jwe
 
-function __go_draw_axes__ (h, plot_stream, enhanced)
+function __go_draw_axes__ (h, plot_stream, enhanced, mono)
 
-  if (nargin == 3)
+  if (nargin == 4)
 
     axis_obj = get (h);
 
@@ -87,7 +87,7 @@
     if (! isempty (axis_obj.xlabel))
       t = get (axis_obj.xlabel);
       angle = t.rotation;
-      colorspec = get_text_colorspec (axis_obj.xcolor);
+      colorspec = get_text_colorspec (axis_obj.xcolor, mono);
       if (isempty (t.string))
        fprintf (plot_stream, "unset xlabel;\n");
        fprintf (plot_stream, "unset x2label;\n");
@@ -123,7 +123,7 @@
     if (! isempty (axis_obj.ylabel))
       t = get (axis_obj.ylabel);
       angle = t.rotation;
-      colorspec = get_text_colorspec (axis_obj.ycolor);
+      colorspec = get_text_colorspec (axis_obj.ycolor, mono);
       if (isempty (t.string))
        fprintf (plot_stream, "unset ylabel;\n");
        fprintf (plot_stream, "unset y2label;\n");
@@ -157,7 +157,7 @@
     if (! isempty (axis_obj.zlabel))
       t = get (axis_obj.zlabel);
       angle = t.rotation;
-      colorspec = get_text_colorspec (axis_obj.zcolor);
+      colorspec = get_text_colorspec (axis_obj.zcolor, mono);
       if (isempty (t.string))
        fputs (plot_stream, "unset zlabel;\n");
       else
@@ -233,7 +233,7 @@
       fputs (plot_stream, "set grid nomztics;\n");
     endif
 
-    do_tics (axis_obj, plot_stream, ymirror);
+    do_tics (axis_obj, plot_stream, ymirror, mono);
 
     xlogscale = strcmpi (axis_obj.xscale, "log");
     if (xlogscale)
@@ -360,7 +360,8 @@
            tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, 
"keylabel", have_newer_gnuplot));
            titlespec{data_idx} = strcat ("title \"", tmp, "\"");
          endif
-         [style, typ, with] = do_linestyle_command (obj, data_idx, 
plot_stream);
+         [style, typ, with] = do_linestyle_command (obj, data_idx,
+                                                    mono, plot_stream);
          usingclause{data_idx} = "";
          if (have_newer_gnuplot || isnan (typ))
            withclause{data_idx} = sprintf ("with %s linestyle %d",
@@ -551,9 +552,14 @@
                endif
 
               if (have_newer_gnuplot)
-                withclause{data_idx} ...
-                    = sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"",
-                               round (255*color));
+                if (mono)
+                  colorspec = "";
+                else
+                  colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                       round (255*color));
+                endif
+                withclause{data_idx} = sprintf ("with filledcurve %s",
+                                                colorspec);
               else
                 if (isequal (color, [0,0,0]))
                   typ = -1;
@@ -730,9 +736,14 @@
             endif
 
             if (have_newer_gnuplot)
-              withclause{data_idx} ...
-                  = sprintf ("with %s %s %s lc rgb \"#%02x%02x%02x\"",
-                             style, pt, ps, round (255*color));
+              if (mono)
+                colorspec = "";
+              else
+                colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                     round (255*color));
+              endif
+              withclause{data_idx} = sprintf ("with %s %s %s %s",
+                                              style, pt, ps, colorspec);
             else
               if (isequal (color, [0,0,0]))
                 typ = -1;
@@ -785,7 +796,7 @@
            parametric(data_idx) = false;
            have_cdata(data_idx) = true;
            [style, typ, with] = do_linestyle_command (obj, data_idx,
-                                                      plot_stream);
+                                                      mono, plot_stream);
            if (isempty (obj.keylabel))
              titlespec{data_idx} = "title \"\"";
            else
@@ -899,9 +910,15 @@
                         data_idx, interp_str, dord);
 
                if (have_newer_gnuplot)
+                 if (mono)
+                   colorspec = "";
+                 else
+                   colorspec = sprintf ("linecolor rgb \"#%02x%02x%02x\"",
+                                        round (255*edgecol));
+                 endif
                   fprintf (plot_stream,
-                           "set style line %d linecolor rgb \"#%02x%02x%02x\" 
lw %f;\n",
-                           data_idx, round (255*edgecol), obj.linewidth);
+                           "set style line %d %s lw %f;\n",
+                           data_idx, colorspec, obj.linewidth);
                else
                  if (isequal (edgecol, [0,0,0]))
                    typ = -1;
@@ -950,7 +967,7 @@
           endif
          
          if (isnumeric (color))
-           colorspec = get_text_colorspec (color);
+           colorspec = get_text_colorspec (color, mono);
          endif
 
          if (nd == 3)
@@ -1182,7 +1199,7 @@
 
 endfunction
 
-function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream)
+function [style, typ, with] = do_linestyle_command (obj, idx, mono, 
plot_stream)
 
   persistent have_newer_gnuplot ...
     = compare_versions (__gnuplot_version__ (), "4.0", ">");
@@ -1200,8 +1217,10 @@
     color = obj.color;
     if (isnumeric (color))
       if (have_newer_gnuplot)
-       fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
-                round (255*color));
+       if (! mono)
+         fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
+                  round (255*color));
+       endif
       else
        if (isequal (color, [0,0,0]))
          typ = -1;
@@ -1398,35 +1417,36 @@
 
 endfunction
 
-function do_tics (obj, plot_stream, ymirror)
+function do_tics (obj, plot_stream, ymirror, mono)
   if (strcmpi (obj.xaxislocation, "top"))
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x2", plot_stream, true);
+              obj.xcolor, "x2", plot_stream, true, mono);
     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x", plot_stream, true);
+              obj.xcolor, "x", plot_stream, true, mono);
   else
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x", plot_stream, true);
+              obj.xcolor, "x", plot_stream, true, mono);
     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x2", plot_stream, true);
+              obj.xcolor, "x2", plot_stream, true, mono);
   endif
   if (strcmpi (obj.yaxislocation, "right"))
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y2", plot_stream, ymirror);
+              obj.ycolor, "y2", plot_stream, ymirror, mono);
     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y", plot_stream, ymirror);
+              obj.ycolor, "y", plot_stream, ymirror, mono);
   else
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y", plot_stream, ymirror);
+              obj.ycolor, "y", plot_stream, ymirror, mono);
     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y2", plot_stream, ymirror);
+              obj.ycolor, "y2", plot_stream, ymirror, mono);
   endif
   do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel,
-            obj.zcolor, "z", plot_stream, true);
+            obj.zcolor, "z", plot_stream, true, mono);
 endfunction
 
-function do_tics_1 (ticmode, tics, labelmode, labels, color, ax, plot_stream, 
mirror)
-  colorspec = get_text_colorspec (color);
+function do_tics_1 (ticmode, tics, labelmode, labels, color, ax,
+                   plot_stream, mirror, mono)
+  colorspec = get_text_colorspec (color, mono);
   if (strcmpi (ticmode, "manual"))
     if (isempty (tics))
       fprintf (plot_stream, "unset %stics;\n", ax);
@@ -1478,13 +1498,17 @@
   endif
 endfunction
 
-function colorspec = get_text_colorspec (color)
+function colorspec = get_text_colorspec (color, mono)
   persistent have_newer_gnuplot ...
       = compare_versions (__gnuplot_version__ (), "4.0", ">");
 
   if (have_newer_gnuplot)
-    colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"",
-                        round (255*color));
+    if (mono)
+      colorspec = "";
+    else
+      colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"",
+                          round (255*color));
+    endif
   else
     if (isequal (color, [0,0,0]))
       typ = -1;
Index: scripts/plot/__go_draw_figure__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__go_draw_figure__.m,v
retrieving revision 1.11
diff -u -u -r1.11 __go_draw_figure__.m
--- scripts/plot/__go_draw_figure__.m   27 Nov 2007 20:16:19 -0000      1.11
+++ scripts/plot/__go_draw_figure__.m   6 Dec 2007 22:02:33 -0000
@@ -20,9 +20,9 @@
 
 ## Author: jwe
 
-function __go_draw_figure__ (f, plot_stream, enhanced)
+function __go_draw_figure__ (f, plot_stream, enhanced, mono)
 
-  if (nargin == 3)
+  if (nargin == 4)
     if (strcmp (f.type, "figure"))
 
       ## Set figure properties here?
@@ -56,7 +56,7 @@
          obj = get (kids(i));
          switch (obj.type)
            case "axes"
-             __go_draw_axes__ (kids (i), plot_stream, enhanced);
+             __go_draw_axes__ (kids (i), plot_stream, enhanced, mono);
            otherwise
              error ("__go_draw_figure__: unknown object class, %s",
                     obj.type);
Index: scripts/plot/drawnow.m
===================================================================
RCS file: /cvs/octave/scripts/plot/drawnow.m,v
retrieving revision 1.28
diff -u -u -r1.28 drawnow.m
--- scripts/plot/drawnow.m      28 Nov 2007 19:00:05 -0000      1.28
+++ scripts/plot/drawnow.m      6 Dec 2007 22:02:33 -0000
@@ -27,7 +27,7 @@
 
 ## Author: jwe
 
-function drawnow (term, file, debug_file)
+function drawnow (term, file, mono, debug_file)
 
   persistent drawnow_executing = 0;
 
@@ -38,7 +38,11 @@
       return;
     endif
 
-    if (nargin == 2 || nargin == 3)
+    if (nargin < 3)
+      mono = false;
+    endif
+
+    if (nargin >= 2 && nargin <= 4)
       h = get (0, "currentfigure");
       if (h)
        f = get (h);
@@ -46,11 +50,11 @@
        fid = [];
        unwind_protect
          [plot_stream, enhanced] = open_gnuplot_stream ([], term, file);
-         __go_draw_figure__ (f, plot_stream, enhanced);        
-         if (nargin == 3)
+         __go_draw_figure__ (f, plot_stream, enhanced, mono);
+         if (nargin == 4)
            fid = fopen (debug_file, "wb");
            enhanced = init_plot_stream (fid, [], term, file);
-           __go_draw_figure__ (f, fid, enhanced);
+           __go_draw_figure__ (f, fid, enhanced, mono);
          endif
        unwind_protect_cleanup
          if (! isempty (plot_stream))
@@ -77,7 +81,7 @@
              else
                enhanced = f.__enhanced__;
              endif
-             __go_draw_figure__ (f, plot_stream, enhanced);
+             __go_draw_figure__ (f, plot_stream, enhanced, mono);
            elseif (! isempty (plot_stream))
              pclose (plot_stream);
              set (h, "__plot_stream__", []);
Index: scripts/plot/print.m
===================================================================
RCS file: /cvs/octave/scripts/plot/print.m,v
retrieving revision 1.31
diff -u -u -r1.31 print.m
--- scripts/plot/print.m        26 Nov 2007 20:42:10 -0000      1.31
+++ scripts/plot/print.m        6 Dec 2007 22:02:33 -0000
@@ -372,10 +372,12 @@
 
   endif
 
+  mono = use_color < 0;
+
   if (debug)
-    drawnow (new_terminal, name, debug_file);
+    drawnow (new_terminal, name, mono, debug_file);
   else
-    drawnow (new_terminal, name);
+    drawnow (new_terminal, name, mono);
   endif
 
   if (! isempty (convertname))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]