changeset 18524:bf0d2e51c8f0 stable

axis.m: make 'tight' embrace whole images (bug #36594). * axis.m (__get_tight_lims__): extend image data limits by one pixel. * image.m: remove duplicate code and call "axis image" when there's no other child in the axes.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 25 Feb 2014 23:56:49 +0100
parents c9ace0567f13
children dd669c2ae76c
files scripts/image/image.m scripts/plot/appearance/axis.m
diffstat 2 files changed, 16 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/image.m	Sat Feb 22 12:22:34 2014 -0800
+++ b/scripts/image/image.m	Tue Feb 25 23:56:49 2014 +0100
@@ -183,28 +183,9 @@
     ## Set axis properties for new images
 
     if (! isempty (img))
-      px = __image_pixel_size__ (h);
-
-      if (xdata(2) < xdata(1))
-        xdata = fliplr (xdata);
-      elseif (xdata(2) == xdata(1))
-        xdata = xdata(1) + [0, columns(img)-1];
+      if (isscalar (get (hax, "children")))
+        axis (hax, "image")
       endif
-      if (ydata(2) < ydata(1))
-        ydata = fliplr (ydata);
-      elseif (ydata(2) == ydata(1))
-        ydata = ydata(1) + [0, rows(img)-1];
-      endif
-      xlim = xdata + [-px(1), px(1)];
-      ylim = ydata + [-px(2), px(2)];
-
-      ## FIXME -- how can we do this and also get the {x,y}limmode
-      ## properties to remain "auto"?  I suppose this adjustment should
-      ## happen automatically in axes::update_axis_limits instead of
-      ## explicitly setting the values here.  But then what information is
-      ## available to axes::update_axis_limits to determine that the
-      ## adjustment is necessary?
-      set (hax, "xlim", xlim, "ylim", ylim);
 
       if (ndims (img) == 3)
         if (isinteger (img))
--- a/scripts/plot/appearance/axis.m	Sat Feb 22 12:22:34 2014 -0800
+++ b/scripts/plot/appearance/axis.m	Tue Feb 25 23:56:49 2014 +0100
@@ -332,10 +332,24 @@
     lims = get (ca, strcat (ax, "lim"));
   else
     data = get (kids, strcat (ax, "data"));
+    types = get (kids, "type");
+    
     scale = get (ca, strcat (ax, "scale"));
     if (! iscell (data))
       data = {data};
     endif
+    
+    ## Extend image data one pixel
+    idx = strcmp (types, "image");
+    if (! isempty (idx) && (ax == "x" || ax == "y"))
+      imdata = data(idx);
+      px = arrayfun (@__image_pixel_size__, kids(idx), "uniformoutput", false);
+      ipx = ifelse (ax == "x", 1, 2);
+      imdata = cellfun (@(x,dx) [(min (x) - dx(ipx)), (max (x) + dx(ipx))],
+                        imdata, px, "uniformoutput", false);
+      data(idx) = imdata;
+    endif
+    
     if (strcmp (scale, "log"))
       tmp = data;
       data = cellfun (@(x) x(x>0), tmp, "uniformoutput", false);