changeset 7726:1b954fdaf4ff

Try to get the colorbar position right for manual aspect ratios as well
author David Bateman <dbateman@free.fr>
date Mon, 21 Apr 2008 11:03:39 -0400
parents 7c9ba697a479
children c8da61051ea2
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/colorbar.m
diffstat 3 files changed, 144 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Sun Apr 20 09:50:22 2008 -0400
+++ b/scripts/ChangeLog	Mon Apr 21 11:03:39 2008 -0400
@@ -1,3 +1,9 @@
+2008-04-21  David Bateman  <dbateman@free.fr>
+
+	* plot/__go_draw_axes__.m (gnuplot_position_colorbox): New arg, obj.
+	Change caller.  Improve sizing and position of colorbox for subplots.
+	* plot/colorbar.m: New demos.
+
 2008-04-16  Soren Hauberg  <hauberg@gmail.com>
 
 	* plot/__gnuplot_version__.m: Display error if gnuplot is not found.
--- a/scripts/plot/__go_draw_axes__.m	Sun Apr 20 09:50:22 2008 -0400
+++ b/scripts/plot/__go_draw_axes__.m	Mon Apr 21 11:03:39 2008 -0400
@@ -51,7 +51,7 @@
 
     if (! strcmpi (get (h, "__colorbar__"), "none"))
       [pos, cbox_orient, cbox_size, cbox_origin, cbox_mirror] = ...
-	  gnuplot_postion_colorbox (pos, get (h, "__colorbar__"));
+	  gnuplot_position_colorbox (pos, get (h, "__colorbar__"), axis_obj);
     endif
 
     fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
@@ -1965,8 +1965,9 @@
   sym.int = '{/Symbol \362}';
 endfunction
 
-function [pos, orient, sz, origin, mirr] = gnuplot_postion_colorbox (pos, cbox)
-  ## This is an emprically derived function that 
+function [pos, orient, sz, origin, mirr] = gnuplot_position_colorbox (pos, cbox, obj)
+  ## This is an emprically derived function that attempts to find a good
+  ## size for the colorbox even for subplots and strange aspect ratios.
 
   if (strncmp (cbox, "north", 5) || strncmp (cbox, "south", 5))
     scl = pos([2,4]);
@@ -1981,45 +1982,74 @@
     endif
   endif
 
+  if (strcmpi (obj.dataaspectratiomode, "manual"))
+    sz = min(pos(3:4))([1,1]);
+    r = obj.dataaspectratio;
+    if (pos(3) > pos(4))
+      switch (cbox)
+	case {"north", "northoutside"}
+	  off = 4 / 3 * [(pos(3) - pos(4)) ./ (r(2)/r(1)), pos(4) / pos(3) / 2];
+	  sz = 2 * sz / 3;
+	case {"south", "southoutside"}
+	  off = 4 / 3 * [(pos(3) - pos(4)) ./ (r(2)/r(1)), 0];
+	  sz = 2 * sz / 3;
+	otherwise
+	  off = [(pos(3) - pos(4)) ./ (r(2)/r(1)), 0];	  
+      endswitch
+    else
+      switch (cbox)
+	case {"north", "northoutside"}
+	  off = 1.5 * [0, (pos(4) - pos(3)) ./ (r(1) / r(2))];
+	case {"south", "southoutside"}
+	  off = 0.5 * [0, (pos(4) - pos(3)) ./ (r(1) / r(2))];
+	otherwise
+	  off = [0, (pos(4) - pos(3)) ./ (r(1) / r(2))];
+      endswitch
+    endif
+    off = off / 2;
+  else
+    sz = pos(3:4);
+    off = 0;
+  endif
   switch (cbox)
     case "northoutside"
-      sz = pos(3:4) - 0.08;
-      origin = [0.05, 0.06] + [0.00, 0.88] .* sz + pos(1:2);
+      sz = sz - 0.08;
+      origin = [0.05, 0.06] + [0.00, 0.88] .* sz + pos(1:2) + off;
       mirr = true;
       orient = "horizontal";
     case "north"
-      sz = pos(3:4) - 0.16;
-      origin = [0.09, 0.09] + [0.00, 0.94] .* sz + pos(1:2);
+      sz = sz - 0.16;
+      origin = [0.09, 0.09] + [0.00, 0.94] .* sz + pos(1:2) + off;
       mirr = false;
       orient = "horizontal";
     case "southoutside"
-      sz = pos(3:4) - 0.08;
-      origin = [0.05, 0.06] + [0.00, 0.00] .* sz + pos(1:2);
+      sz = sz - 0.08;
+      origin = [0.05, 0.06] + [0.00, 0.00] .* sz + pos(1:2) + off;
       mirr = false;
       orient = "horizontal";
     case "south"
-      sz = pos(3:4) - 0.16;
-      origin = [0.08, 0.09] + [0.03, 0.05] .* sz + pos(1:2);
+      sz = sz - 0.16;
+      origin = [0.08, 0.09] + [0.03, 0.05] .* sz + pos(1:2) + off;
       mirr = true;
       orient = "horizontal";
     case "eastoutside"
-      sz = pos(3:4) - 0.08;
-      origin = [0.00, 0.06] + [0.94, 0.00] .* sz + pos(1:2);
+      sz = sz - 0.08;
+      origin = [0.00, 0.06] + [0.94, 0.00] .* sz + pos(1:2) + off;
       mirr = false;
       orient = "vertical";
     case "east"
-      sz = pos(3:4) - 0.16;
-      origin = [0.09, 0.10] + [0.91, 0.01] .* sz + pos(1:2);
+      sz = sz - 0.16;
+      origin = [0.09, 0.10] + [0.91, 0.01] .* sz + pos(1:2) + off;
       mirr = true;
       orient = "vertical";
     case "westoutside"
-      sz = pos(3:4) - 0.08;
-      origin = [0.00, 0.06] + [0.06, 0.00] .* sz + pos(1:2);
+      sz = sz - 0.08;
+      origin = [0.00, 0.06] + [0.06, 0.00] .* sz + pos(1:2) + off;
       mirr = true;
       orient = "vertical";
     case "west"
-      sz = pos(3:4) - 0.16;
-      origin = [0.06, 0.09] + [0.04, 0.03] .* sz + pos(1:2);
+      sz = sz - 0.16;
+      origin = [0.06, 0.09] + [0.04, 0.03] .* sz + pos(1:2) + off;
       mirr = false;
       orient = "vertical";
   endswitch
--- a/scripts/plot/colorbar.m	Sun Apr 20 09:50:22 2008 -0400
+++ b/scripts/plot/colorbar.m	Mon Apr 21 11:03:39 2008 -0400
@@ -148,3 +148,92 @@
 %! imagesc(x)
 %! colorbar("southoutside");
 
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! imagesc(x)
+%! axis square;
+%! colorbar();
+%! subplot(1,2,2)
+%! imagesc(x)
+%! axis square;
+%! colorbar("westoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! imagesc(x)
+%! axis square;
+%! colorbar("northoutside");
+%! subplot(1,2,2)
+%! imagesc(x)
+%! axis square;
+%! colorbar("southoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(2,1,1)
+%! imagesc(x)
+%! axis square;
+%! colorbar();
+%! subplot(2,1,2)
+%! imagesc(x)
+%! axis square;
+%! colorbar("westoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(2,1,1)
+%! imagesc(x)
+%! axis square;
+%! colorbar("northoutside");
+%! subplot(2,1,2)
+%! imagesc(x)
+%! axis square;
+%! colorbar("southoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! imagesc(x)
+%! colorbar();
+%! subplot(1,2,2)
+%! imagesc(x)
+%! colorbar("westoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! imagesc(x)
+%! colorbar("northoutside");
+%! subplot(1,2,2)
+%! imagesc(x)
+%! colorbar("southoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(2,1,1)
+%! imagesc(x)
+%! colorbar();
+%! subplot(2,1,2)
+%! imagesc(x)
+%! colorbar("westoutside");
+
+%!demo
+%! hold off;
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(2,1,1)
+%! imagesc(x)
+%! colorbar("northoutside");
+%! subplot(2,1,2)
+%! imagesc(x)
+%! colorbar("southoutside");
+
+