octave-maintainers
[Top][All Lists]
Advanced

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

patch with gnuplot 4.0, etc


From: David Bateman
Subject: patch with gnuplot 4.0, etc
Date: Mon, 10 Sep 2007 22:38:56 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

The attached patch allows gnuplot 4.0 to be used with the patch, but
limits the allowed colours in the same way as for line. It also changes
patch to allow matrix arguments with one patch per column, Finally, it
actually uses the patch type for something as the it rewrites the
bar/barh functions to use patch.

Regards
David

Index: scripts/plot/__bar__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__bar__.m,v
retrieving revision 1.3
diff -c -r1.3 __bar__.m
*** scripts/plot/__bar__.m      17 May 2007 19:44:28 -0000      1.3
--- scripts/plot/__bar__.m      10 Sep 2007 20:32:07 -0000
***************
*** 75,84 ****
        idx++;
      else
        if ((isstr(varargin{idx}) || iscell(varargin{idx})) && !HaveLineSpec)
!       [dummy, valid] = __pltopt__ (func, varargin{idx}, false);
        if (valid)
          HaveLineSpec = true;
!         newargs = [newargs,varargin(idx++)];
          continue;
        endif
        endif
--- 75,85 ----
        idx++;
      else
        if ((isstr(varargin{idx}) || iscell(varargin{idx})) && !HaveLineSpec)
!       [linespec, valid] = __pltopt__ (func, varargin{idx}, false);
        if (valid)
          HaveLineSpec = true;
!         newargs = [{linespec.color}, newargs];
!         idx++;
          continue;
        endif
        endif
***************
*** 113,128 ****
    delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width;
    x1 = (x - delta_m)(:)';
    x2 = (x + delta_p)(:)';
!   xb = repmat([x1; x1; x2; x2; NaN * ones(1,ylen)](:), 1, ycols);
  
    if (group)
      width = width / ycols;
      offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]);
!     xb(1:5:5*ylen,:) += offset;
!     xb(2:5:5*ylen,:) += offset;
!     xb(3:5:5*ylen,:) += offset;
!     xb(4:5:5*ylen,:) += offset;
!     xb(5:5:5*ylen,:) += offset;
      y0 = zeros (size (y));
      y1 = y;
    else
--- 114,128 ----
    delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width;
    x1 = (x - delta_m)(:)';
    x2 = (x + delta_p)(:)';
!   xb = repmat([x1; x1; x2; x2](:), 1, ycols);
  
    if (group)
      width = width / ycols;
      offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]);
!     xb(1:4:4*ylen,:) += offset;
!     xb(2:4:4*ylen,:) += offset;
!     xb(3:4:4*ylen,:) += offset;
!     xb(4:4:4*ylen,:) += offset;
      y0 = zeros (size (y));
      y1 = y;
    else
***************
*** 130,156 ****
      y0 = [zeros(ylen,1), y1(:,1:end-1)];
    endif
  
!   yb = zeros (5*ylen, ycols);
!   yb(1:5:5*ylen,:) = y0;
!   yb(2:5:5*ylen,:) = y1;
!   yb(3:5:5*ylen,:) = y1;
!   yb(4:5:5*ylen,:) = y0;
!   yb(5:5:5*ylen,:) = NaN;
  
    if (vertical)
      if (nargout < 1)
!       plot (xb, yb, newargs{:});
      elseif (nargout < 2)
!       varargout{1} = plot (xb, yb, newargs{:});
      else
        varargout{1} = xb;
        varargout{2} = yb;
      endif
    else
      if (nargout < 1)
!       plot (yb, xb, newargs{:});
      elseif (nargout < 2)
!       varargout{1} = plot (yb, xb, newargs{:});
      else
        varargout{1} = yb;
        varargout{2} = xb;
--- 130,164 ----
      y0 = [zeros(ylen,1), y1(:,1:end-1)];
    endif
  
!   yb = zeros (4*ylen, ycols);
!   yb(1:4:4*ylen,:) = y0;
!   yb(2:4:4*ylen,:) = y1;
!   yb(3:4:4*ylen,:) = y1;
!   yb(4:4:4*ylen,:) = y0;
! 
!   xb = reshape (xb, 4, numel (xb) /  4);
!   yb = reshape (yb, 4, numel (yb) /  4);
! 
!   if (! HaveLineSpec)
!     colors = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1];
!     newargs = [{shiftdim(colors (mod (floor ([0 : (ycols * ylen - 1)] / 
ylen), 
!                                     6) + 1, :), -1)}, newargs];
!   endif
  
    if (vertical)
      if (nargout < 1)
!       patch (xb, yb, newargs {:});
      elseif (nargout < 2)
!       varargout{1} = patch (xb, yb, newargs {:});
      else
        varargout{1} = xb;
        varargout{2} = yb;
      endif
    else
      if (nargout < 1)
!       patch (yb, xb, newargs{:});
      elseif (nargout < 2)
!       varargout{1} = patch (yb, xb, newargs{:});
      else
        varargout{1} = yb;
        varargout{2} = xb;
Index: scripts/plot/__go_draw_axes__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__go_draw_axes__.m,v
retrieving revision 1.36
diff -c -r1.36 __go_draw_axes__.m
*** scripts/plot/__go_draw_axes__.m     5 Sep 2007 06:15:01 -0000       1.36
--- scripts/plot/__go_draw_axes__.m     10 Sep 2007 20:32:08 -0000
***************
*** 427,479 ****
          endif
  
         case "patch"
!          if (! have_newer_gnuplot)
!            warning ("patch objects require gnuplot v4.2 or later!, sorry")
!          else
!          if (! isempty (obj.zdata))
!              warning ("gnuplot (as of v4.2) supports only 2D patches, 
ignoring z values")
!          endif
!          nd = 2;
!            cmap = parent_figure_obj.colormap;
!            clim = axis_obj.clim;
!          data_idx++;
!          is_image_data(data_idx) = false;
!          parametric(data_idx) = false;
!            titlespec{data_idx} = "title \"\"";
!          usingclause{data_idx} = "";
!            if (isfield (obj, "facecolor") && isfield (obj, "cdata"))
!              if (strncmp (obj.facecolor, "none", 4))
!              color = [1, 1, 1];
!              elseif (strncmp (obj.facecolor, "flat", 4))
!                r = 1 + round ((size (cmap, 1) - 1) * (obj.cdata - 
clim(1))/(clim(2) - clim(1)));
!                r = max (1, min (r, size (cmap, 1)));
!              color = cmap(r,:);
!              elseif (strncmp (obj.facecolor, "interp", 6))
!                warning ("\"interp\" not supported, using 1st entry of cdata")
!                r = 1 + round ((size (cmap, 1) - 1) * obj.cdata(1));
!                r = max (1, min (r, size (cmap, 1)));
!              color = cmap(r,:);
!              else
!              color = obj.facecolor;
!              endif
             else
!              color = [1, 0, 0];
             endif
  
           withclause{data_idx} = sprintf ("with filledcurve lc rgb 
\"#%02x%02x%02x\"",round (255*color));
  
!          xdat = obj.xdata(:);
!          ydat = obj.ydata(:);
  
!          if (xautoscale)
!              [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat);
!          endif
!          if (yautoscale)
!            [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
!          endif
!          data{data_idx} = [xdat, ydat]';
!          usingclause{data_idx} = "using ($1):($2)";
         endif
  
           ## patch outline
           data_idx++;
--- 427,498 ----
          endif
  
         case "patch"
!        if (! isempty (obj.zdata))
!            warning ("gnuplot (as of v4.2) supports only 2D patches, ignoring 
z values")
!        endif
!        nd = 2;
!          cmap = parent_figure_obj.colormap;
!          clim = axis_obj.clim;
!        data_idx++;
!        is_image_data(data_idx) = false;
!        parametric(data_idx) = false;
!          titlespec{data_idx} = "title \"\"";
!        usingclause{data_idx} = "";
!          if (isfield (obj, "facecolor") && isfield (obj, "cdata"))
!            if (strncmp (obj.facecolor, "none", 4))
!            color = [1, 1, 1];
!            elseif (strncmp (obj.facecolor, "flat", 4))
!              r = 1 + round ((size (cmap, 1) - 1) * (obj.cdata - 
clim(1))/(clim(2) - clim(1)));
!              r = max (1, min (r, size (cmap, 1)));
!            color = cmap(r,:);
!            elseif (strncmp (obj.facecolor, "interp", 6))
!              warning ("\"interp\" not supported, using 1st entry of cdata")
!              r = 1 + round ((size (cmap, 1) - 1) * obj.cdata(1));
!              r = max (1, min (r, size (cmap, 1)));
!            color = cmap(r,:);
             else
!            color = obj.facecolor;
             endif
+          else
+            color = [1, 0, 0];
+          endif
  
+        if (have_newer_gnuplot)
           withclause{data_idx} = sprintf ("with filledcurve lc rgb 
\"#%02x%02x%02x\"",round (255*color));
+        else
+          if (isequal (color, [0,0,0]))
+            typ = -1;
+          elseif (isequal (color, [1,0,0]))
+            typ = 1;
+          elseif (isequal (color, [0,1,0]))
+            typ = 2;
+          elseif (isequal (color, [0,0,1]))
+            typ = 3;
+          elseif (isequal (color, [1,0,1]))
+            typ = 4;
+          elseif (isequal (color, [0,1,1]))
+            typ = 5;
+          elseif (isequal (color, [1,1,1]))
+            typ = -1;
+          elseif (isequal (color, [1,1,0]))
+            typ = 7;
+          else
+            typ = -1;
+          endif
+          withclause{data_idx} = sprintf ("with filledcurve lt %d", typ);
+        endif
  
!        xdat = obj.xdata(:);
!        ydat = obj.ydata(:);
  
!        if (xautoscale)
!            [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat);
!        endif
!        if (yautoscale)
!          [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
         endif
+        data{data_idx} = [xdat, ydat]';
+        usingclause{data_idx} = "using ($1):($2)";
  
           ## patch outline
           data_idx++;
***************
*** 496,502 ****
           else
             color = [0, 0, 0];
           endif
!        withclause{data_idx} = sprintf ("with lines lc rgb 
\"#%02x%02x%02x\"",round (255*color));
  
           xdat = [xdat; xdat(1)];
         ydat = [ydat; ydat(1)];
--- 515,544 ----
           else
             color = [0, 0, 0];
           endif
!        if (have_newer_gnuplot)
!          withclause{data_idx} = sprintf ("with lines lc rgb 
\"#%02x%02x%02x\"",round (255*color));
!        else
!          if (isequal (color, [0,0,0]))
!            typ = -1;
!          elseif (isequal (color, [1,0,0]))
!            typ = 1;
!          elseif (isequal (color, [0,1,0]))
!            typ = 2;
!          elseif (isequal (color, [0,0,1]))
!            typ = 3;
!          elseif (isequal (color, [1,0,1]))
!            typ = 4;
!          elseif (isequal (color, [0,1,1]))
!            typ = 5;
!          elseif (isequal (color, [1,1,1]))
!            typ = -1;
!          elseif (isequal (color, [1,1,0]))
!            typ = 7;
!          else
!            typ = -1;
!          endif
!          withclause{data_idx} = sprintf ("with lines lt %d", typ);
!        endif
  
           xdat = [xdat; xdat(1)];
         ydat = [ydat; ydat(1)];
Index: scripts/plot/__patch__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__patch__.m,v
retrieving revision 1.1
diff -c -r1.1 __patch__.m
*** scripts/plot/__patch__.m    10 Aug 2007 17:34:59 -0000      1.1
--- scripts/plot/__patch__.m    10 Sep 2007 20:32:08 -0000
***************
*** 27,103 ****
  
  function h = __patch__ (p, varargin)
  
!   if (nargin < 1)
      print_usage ();
    endif
  
!   nvargs = numel (varargin);
! 
!   if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2}))
!     num_data_args = 2;
!   else
!     num_data_args = 0;
    endif
  
!   if (rem (nvargs - num_data_args - 1, 2) == 0 && nvargs > 2)
!   else
!     print_usage ("patch");
    endif
  
!   x = varargin{1};
!   y = varargin{2};
!   c = varargin{3};
! 
!   h = __go_patch__ (p);
!   ax = get (h, "parent");
!   if (num_data_args > 1)
!     set (h, "xdata", x, "ydata", y);
    endif
  
!   if (isstr (c))
!     ## Have color string.
!     set (h, "FaceColor", c);
!   elseif (length (c) == 1)
!     if (isnan (c))
!       set (h, "FaceColor", [1, 1, 1]);
!       set (h, "CData", c);
!     elseif (isnumeric (c))
!       ## Have color index.
!       set (h, "FaceColor", "flat");
!       set (h, "CData", c);
! 
!       clim = get(ax, "CLim");
!       if (c < clim(1))
!         set (ax, "CLim", [c, clim(2)])
        endif
!       if (c > clim(2))
!         set (ax, "CLim", [clim(1), c])
!       end
! 
!     else
!       ## Unknown color value.
!       error ("color value not valid");
!     end
!   elseif (length (c) == 3)
!     ## Have rgb/rgba value.
!     set (h, "FaceColor", c);
!   else
!     ## Color vector.
!     if (length (c) != length (x) || length (c) != length (y))
!       error ("size of x, y, and c must be equal")
!     else
!       set (h, "FaceColor", "interp");
!       set(h, "CData", c);
!       if (abs(max(c) - min(c)) < eps)
!         set (ax, "CLim", [c(1)-1, c(1)+1])
        else
!         set (ax, "CLim", [min(c), max(c)]);
!       end
!     end
!   end 
  
!   if (nvargs > num_data_args + 1)
!     set (h, varargin{num_data_args+2:end});
    endif
- 
  endfunction
--- 27,146 ----
  
  function h = __patch__ (p, varargin)
  
!   if (nargin < 3)
      print_usage ();
    endif
  
!   iarg = 1;
!   have_x = have_z = have_c = false;
!   if (isnumeric (varargin {1}))
!     if (!isnumeric (varargin {2}))
!       print_usage ();
!     endif
! 
!     x = varargin {1};
!     y = varargin {2};
!     have_x = true;
!     iarg += 2;
! 
!     if (nargin > 3 && ndims (varargin {3}) == 2 && 
!       size (varargin {3}) == size (x))
!       z = varargin {3};
!       have_z = true;
!       iarg ++;
!     endif
    endif
  
!   if (have_x && nargin > iarg && isnumeric (varargin {iarg}))
!     c = varargin {iarg};
!     have_c = true;
!     iarg ++;
! 
!     if (ndims (c) == 3 && size (c, 2) == 1)
!       c = permute (c, [1, 3, 2]);
!     endif
    endif
  
!   if (rem (nargin - iarg, 2) != 0)
!     print_usage ();
    endif
  
!   if (have_x)
!     if (isvector (x))
!       x = x(:);
!       y = y(:);
!       if (have_z)
!       z = z(:);
        endif
!     endif
! 
!     [nr, nc] = size (x);
! 
!     for i = 1 : nc
!       h = __go_patch__ (p);
!       ax = get (h, "parent");
!       if (have_x)
!       set (h, "xdata", x (:, i), "ydata", y (:, i));
!       if (have_z)
!         set (h, "zdata", z (:, i));
!       endif
!       endif
! 
!       if (have_c)
!       if (ndims (c) == 2 && ((nr > 3 && size (c, 2) == nc) ||
!                              (size (c, 1) > 1 && size (c, 2) == nc)))
!         c2 = c (:, i);
!       elseif (ndims (c) == 3)
!         c2 = permute (c (:, i, :), [1, 3, 2]);
!       else
!         c2 = c;
!       endif
! 
!       if (numel (c2) == 1)
!         if (isnan (c))
!           set (h, "FaceColor", [1, 1, 1]);
!           set (h, "CData", c2);
!         elseif (isnumeric (c2))
!           ## Have color index.
!           set (h, "FaceColor", "flat");
!           set (h, "CData", c2);
!           clim = get(ax, "CLim");
!           if (c2 < clim(1))
!               set (ax, "CLim", [c2, clim(2)])
!           endif
!           if (c2 > clim(2))
!               set (ax, "CLim", [clim(1), c2])
!           endif
!         else
!           ## Unknown color value.
!           error ("color value not valid");
!         endif
!       elseif (numel (c2) == 3)
!         ## Have rgb/rgba value.
!         set (h, "FaceColor", c2);
!       else
!         ## Color vector.
!         if (length (c2) != length (x) || length (c2) != length (y))
!           error ("size of x, y, and c must be equal")
!         else
!           set (h, "FaceColor", "interp");
!           set(h, "CData", c2);
!           if (abs(max(c2) - min(c2)) < eps)
!               set (ax, "CLim", [c2(1)-1, c2(1)+1])
!           else
!               set (ax, "CLim", [min(c2), max(c2)]);
!           endif
!         endif
!       endif
        else
!       set (h, "FaceColor", [0, 1, 0]);
!       endif
  
!       if (nargin > iarg + 1)
!       set (h, varargin{iarg:end});
!       endif
!     endfor
!   else
!     error ("Not supported");
    endif
  endfunction
2007-09-10  David Bateman  <address@hidden>

        * plot/__go_draw_axes__.m: Allow gnuplot 4.0 with patches, but
        limit the selection of colors in the same way as for lines.
        * plot/__patch__.m: Allow matrix arguments with one patch per
        column.
        * plot/__bar__.m: Adapt to use "patch".

reply via email to

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