octave-maintainers
[Top][All Lists]
Advanced

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

Re: caxis and a couple of other axis changes...


From: David Bateman
Subject: Re: caxis and a couple of other axis changes...
Date: Thu, 15 Nov 2007 23:50:53 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

David Bateman wrote:
> Here is a patch that adds the caxis function and allows the axis
> function to accept a function handle as the first argument. There are
> also a couple of doc fixes associated with this and some modification to
> __go_draw_axes__.m to allow the caxis to be correctly set manually.
> 
> D.
> 

I found a small issue with the help string of the caxis function, please
use the attached version instead.

D.

*** ./scripts/plot/axis.m.orig10        2007-11-15 11:52:43.366030565 +0100
--- ./scripts/plot/axis.m       2007-11-15 13:55:07.302129898 +0100
***************
*** 29,35 ****
  ## Without any arguments, @code{axis} turns autoscaling on.  
  ##
  ## With one output argument, @code{x=axis} returns the current axes 
- ## (this is not yet implemented for automatic axes).
  ##
  ## The vector argument specifying limits is optional, and additional
  ## string arguments may be used to specify various axis properties.  For
--- 29,34 ----
***************
*** 109,125 ****
  ## Restore y-axis, so higher values are nearer the top. 
  ## @end table
  ## 
  ## @end deftypefn
  
  ## Author: jwe
  
  ## PKG_ADD: mark_as_command axis
  
! function curr_axis = axis (ax, varargin)
  
!   ca = gca ();
  
!   if (nargin == 0)
      if (nargout == 0)
        set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
      else
--- 108,154 ----
  ## Restore y-axis, so higher values are nearer the top. 
  ## @end table
  ## 
+ ## If an axes handle is passed as the first argument, then operate on
+ ## this axes rather than the current axes.
  ## @end deftypefn
  
  ## Author: jwe
  
  ## PKG_ADD: mark_as_command axis
  
! function varargout = axis (varargin)
  
!   if (nargin > 0 && isscalar (varargin{1}) && ishandle (varargin{1}))
!     h = varargin{1};
!     if (! strcmp (get (h, "type"), "axes"))
!       error ("axis: expecting first argument to be an axes object");
!     endif
!     oldh = gca ();
!     unwind_protect
!       axes (h);
!       varargout = cell (max (nargin == 1, nargout), 1);
!       if (isempty (varargout))
!       __axis__ (h, varargin{2:end});
!       else
!         [varargout{:}] = __axis__ (h, varargin{2:end});
!       endif
!     unwind_protect_cleanup
!       axes (oldh);
!     end_unwind_protect
!   else
!     varargout = cell (max (nargin == 0, nargout), 1);
!     if (isempty (varargout))
!       __axis__ (gca (), varargin{:});
!     else
!       [varargout{:}] = __axis__ (gca (), varargin{:});
!     endif
!   endif
! 
! endfunction
! 
! function curr_axis = __axis__ (ca, ax, varargin)
  
!   if (nargin == 1)
      if (nargout == 0)
        set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
      else
***************
*** 254,261 ****
      error ("axis: expecting no args, or a vector with 2, 4, or 6 elements");
    endif
  
!   if (nargin > 1)
!     axis (varargin{:});
    endif
  
  endfunction
--- 283,290 ----
      error ("axis: expecting no args, or a vector with 2, 4, or 6 elements");
    endif
  
!   if (nargin > 2)
!     __axis__ (ca, varargin{:});
    endif
  
  endfunction
*** ./scripts/plot/__go_draw_axes__.m.orig10    2007-11-15 12:50:23.187041279 
+0100
--- ./scripts/plot/__go_draw_axes__.m   2007-11-15 12:48:19.807337073 +0100
***************
*** 438,443 ****
--- 438,452 ----
           clim = axis_obj.clim;
         [nr, nc] = size (obj.xdata);
  
+        if (! isempty (obj.cdata))
+          cdat = obj.cdata;
+          if (cautoscale)
+            [cmin, cmax, cminp] = get_data_limits (cmin, cmax, cminp, cdat);
+          endif
+        else
+          cdat = [];
+        endif
+ 
         for i = 1:nc
           xcol = obj.xdata(:,i);
           ycol = obj.ydata(:,i);
***************
*** 491,501 ****
                       && ((nr > 3 && size (obj.cdata, 2) == nc)
                           || (size (obj.cdata, 1) > 1
                               && size (obj.cdata, 2) == nc)))
!                    ccol = obj.cdata (:, i);
                   elseif (ndims (obj.cdata) == 3)
!                    ccol = permute (obj.cdata (:, i, :), [1, 3, 2]);
                   else
!                    ccol = obj.cdata;
                   endif
                   if (strncmp (obj.facecolor, "flat", 4))
                     if (numel(ccol) == 3)
--- 500,510 ----
                       && ((nr > 3 && size (obj.cdata, 2) == nc)
                           || (size (obj.cdata, 1) > 1
                               && size (obj.cdata, 2) == nc)))
!                    ccol = cdat (:, i);
                   elseif (ndims (obj.cdata) == 3)
!                    ccol = permute (cdat (:, i, :), [1, 3, 2]);
                   else
!                    ccol = cdat;
                   endif
                   if (strncmp (obj.facecolor, "flat", 4))
                     if (numel(ccol) == 3)
***************
*** 571,581 ****
                     && ((nr > 3 && size (obj.cdata, 2) == nc)
                         || (size (obj.cdata, 1) > 1
                             && size (obj.cdata, 2) == nc)))
!                  ccol = obj.cdata (:, i);
                 elseif (ndims (obj.cdata) == 3)
!                  ccol = permute (obj.cdata (:, i, :), [1, 3, 2]);
                 else
!                  ccol = obj.cdata;
                 endif
                 if (strncmp (obj.edgecolor, "flat", 4))
                   if (numel (ccol) == 3)
--- 580,590 ----
                     && ((nr > 3 && size (obj.cdata, 2) == nc)
                         || (size (obj.cdata, 1) > 1
                             && size (obj.cdata, 2) == nc)))
!                  ccol = cdat (:, i);
                 elseif (ndims (obj.cdata) == 3)
!                  ccol = permute (cdat (:, i, :), [1, 3, 2]);
                 else
!                  ccol = cdat;
                 endif
                 if (strncmp (obj.edgecolor, "flat", 4))
                   if (numel (ccol) == 3)
***************
*** 735,741 ****
            fputs (plot_stream, "set style data lines;\n");
            fputs (plot_stream, "set surface;\n");
            fputs (plot_stream, "unset contour;\n");
-           fprintf (plot_stream, "set cbrange [%g:%g];\n", cmin, cmax);
  
            ## Interpolation does not work for flat surfaces (e.g. pcolor)
              ## and color mapping --> currently set empty.
--- 744,749 ----
***************
*** 964,969 ****
--- 972,987 ----
        fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir);
      endif
  
+     if (cautoscale && have_data)
+       clim = [cmin, cmax];
+       set (h, "clim", clim, "climmode", "auto");
+     else
+       clim = axis_obj.clim;
+     endif
+     if (! any (isinf (clim)))
+       fprintf (plot_stream, "set cbrange [%g:%g];\n", clim);
+     endif
+ 
      if (strcmpi (axis_obj.box, "on"))
        if (nd == 3)
        fputs (plot_stream, "set border 4095;\n");
*** ./scripts/plot/caxis.m.orig10       2007-11-15 12:50:36.550360987 +0100
--- ./scripts/plot/caxis.m      2007-11-15 23:48:58.162897492 +0100
***************
*** 0 ****
--- 1,102 ----
+ ## Copyright (C)  2007 David Bateman
+ ##
+ ## This file is part of Octave.
+ ##
+ ## Octave is free software; you can redistribute it and/or modify it
+ ## under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation; either version 3 of the License, or (at
+ ## your option) any later version.
+ ##
+ ## Octave is distributed in the hope that it will be useful, but
+ ## WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with Octave; see the file COPYING.  If not, see
+ ## <http://www.gnu.org/licenses/>.
+ 
+ ## -*- texinfo -*-
+ ## @deftypefn {Function File} {} caxis (@var{limits})
+ ## @deftypefnx {Function File} {} caxis (@var{h}, @dots{})
+ ## Set color axis limits for plots.
+ ##
+ ## The argument @var{limits} should be a 2 element vector specifying the 
+ ## lower and upper limits to assign to the first and last value in the
+ ## colormap. Values outside this range are clamped to the first and last
+ ## colormap entries. 
+ ##
+ ## If @var{limits} is 'auto', then automatic colormap scaling is applied,
+ ## whereas if @var{limits} is 'manual' the colormap scaling is set to manual.
+ ##
+ ## Called without any arguments to current color axis limits are returned.
+ ##
+ ## If an axes handle is passed as the first argument, then operate on
+ ## this axes rather than the current axes.
+ ## @end deftypefn
+ 
+ ## PKG_ADD: mark_as_command caxis
+ 
+ function varargout = caxis (varargin)
+ 
+   if (nargin > 0 && isscalar (varargin{1}) && ishandle (varargin{1}))
+     h = varargin{1};
+     if (! strcmp (get (h, "type"), "axes"))
+       error ("caxis: expecting first argument to be an axes object");
+     endif
+     oldh = gca ();
+     unwind_protect
+       axes (h);
+       varargout = cell (max (nargin == 1, nargout), 1);
+       if (isempty (varargout))
+       __caxis__ (h, varargin{2:end});
+       else
+         [varargout{:}] = __caxis__ (h, varargin{2:end});
+       endif
+     unwind_protect_cleanup
+       axes (oldh);
+     end_unwind_protect
+   else
+     varargout = cell (max (nargin == 0, nargout), 1);
+     if (isempty (varargout))
+       __caxis__ (gca (), varargin{:});
+     else
+       [varargout{:}] = __caxis__ (gca (), varargin{:});
+     endif
+   endif
+ 
+ endfunction
+ 
+ function [cmin, cmax] = __caxis__ (ca, ax, varargin)
+ 
+   if (nargin == 1)
+     cmin = get (ca, "clim");
+     if (nargout > 1)
+       cmax = cmin(2);
+       cmin = cmin(1);
+     endif
+   elseif (ischar (ax))
+     ax = tolower (ax);
+     if (strcmp (ax, "auto"))
+       set (ca, "climmode", "auto");
+     elseif (strcmp (ax, "manual"))
+       set (ca, "climmode", "manual");
+     endif
+   elseif (isvector (ax))
+     len = length (ax);
+ 
+     if (len != 2)
+       error ("caxis: expecting vector with 2 elements");
+     endif
+ 
+     set (ca, "clim", [ax(1), ax(2)]);
+   else
+     error ("caxis: expecting no args, a string or a 2 element vector");
+   endif
+ 
+   if (nargin > 2)
+     __caxis__ (ca, varargin{:})'
+   endif
+ 
+ endfunction
+       
*** ./doc/interpreter/plot.txi.orig10   2007-11-15 13:45:51.910708755 +0100
--- ./doc/interpreter/plot.txi  2007-11-15 13:46:44.292014363 +0100
***************
*** 189,194 ****
--- 189,199 ----
  
  @DOCSTRING(axis)
  
+ Similar the axis limits of the colormap can be changed with the caxis
+ function.
+ 
+ @DOCSTRING(caxis)
+ 
  @node Three-Dimensional Plotting
  @subsection Three-Dimensional Plotting
  
2007-11-15  David Bateman  <address@hidden>

        * plot/caxis.m: New function to control the color axis limits.
        * plot/Makefile.in (SOURCES): Include it.
        * plot/axis.m: Allow the first argument to be an axes handle.
        * plot/__go_draw_axes__.m: Move the setting of the caxis, also
        autoscale caxis for patches. If any(isinf(clim)) don't set the
        caxis limits.

2007-11-15  David Bateman  <address@hidden>

        * interpreter/plot.txi: Document caxis.

reply via email to

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