octave-maintainers
[Top][All Lists]
Advanced

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

axis tight patch


From: Bill Denney
Subject: axis tight patch
Date: Sun, 06 Jan 2008 11:19:29 -0500
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Hello,

I just want to congratulate everyone on the release of version 3.0.0.

I was looking through some of the new plot functions, and I noticed that axis tight didn't work as expected, so here is a patch that makes it work.

Thanks,

Bill

scripts/Changelog
2008-01-06  Bill Denney  <address@hidden>
   * plot/axis.m: fix axis tight (and axis image)
Index: axis.m
===================================================================
RCS file: /cvs/octave/scripts/plot/axis.m,v
retrieving revision 1.47
diff -u -r1.47 axis.m
--- axis.m      29 Nov 2007 19:07:29 -0000      1.47
+++ axis.m      6 Jan 2008 16:15:07 -0000
@@ -160,8 +160,10 @@
       ## aspect ratio
     elseif (strcmp (ax, "image"))
       set (ca, "dataaspectratio", [1, 1, 1]);
-      ## FIXME should be the same as "tight"
-      set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
+      ## also make the axis tight
+      if (~ strcmp (varargin, "tight")) || isempty (varargin)
+        varargin{end+1} = "tight";
+      endif
     elseif (strcmp (ax, "equal") || strcmp (ax, "square"))
       set (ca, "dataaspectratio", [1, 1, 1]);
     elseif (strcmp (ax, "normal"))
@@ -186,10 +188,12 @@
       ## fixes the axis limits, like axis(axis) should;
       set (ca, "xlimmode", "manual", "ylimmode", "manual", "zlimmode", 
"manual");
     elseif (strcmp (ax, "tight"))
-      ## FIXME if tight, plot must set ranges to limits of the
-      ## all the data on the current plot, even if from a previous call.
-      ## Instead, just let gnuplot do as it likes.
-      set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
+      ## sets the axis limits to the min and max of all data.
+      set (ca, "xlimmode", "manual", "ylimmode", "manual",
+           "zlimmode", "manual",
+           "xlim", __get_tight_lims__(ca, "x"),
+           "ylim", __get_tight_lims__(ca, "y"),
+           "zlim", __get_tight_lims__(ca, "z"));
 
       ## tic marks
     elseif (strcmp (ax, "on") || strcmp (ax, "tic"))
@@ -272,12 +276,32 @@
     error ("axis: expecting no args, or a vector with 2, 4, or 6 elements");
   endif
 
-  if (nargin > 2)
+  if (~ isempty (varargin))
     __axis__ (ca, varargin{:});
   endif
 
 endfunction
 
+function lims = __get_tight_lims__(ca, ax)
+
+  ## get the limits for axis("tight")
+  ## ax should be one of "x", "y", or "z"
+  kids = findobj (ca, "-property", [ax "data"]);
+  if isempty (kids)
+    # return the current limits
+    lims = get (ca, [ax "lim"]);
+  else
+    data = get (kids, [ax "data"]);
+    if iscell (data)
+      lims(1) = min (cellfun (@min, data));
+      lims(2) = min (cellfun (@max, data));
+    else
+      lims = [min(data) max(data)];
+    end
+  end
+
+endfunction
+
 %!demo
 %! t=0:0.01:2*pi; x=sin(t);
 %!

reply via email to

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