help-octave
[Top][All Lists]
Advanced

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

[CHANGESET] Re: stange 'colorbar' command behavior


From: David Bateman
Subject: [CHANGESET] Re: stange 'colorbar' command behavior
Date: Mon, 21 Apr 2008 12:12:54 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

address@hidden wrote:
> Hi,
>
> I have just installed Octave 3.0.0 from the source on Ubuntu Linux 7.10.
> One of my concerns from working with Octave 2.9 was that the colorbar
> command did not show numbers on the colour bar. To my delight, after
> making a sequence of commands
>
> imagesc(randn(200))
> axis square
> colorbar
>
> I discovered that imagesc works, axes tics are tight around the image and
> the colour bar shows the numbers on it. However, after installation of a
> few octave-forge packages including those for plotting: image, plot,
> zenity, to my surprise, the second try of the commands above resulted in
> colour bar without numbers! I have no idea what exactly happened and how
> to return the things to initial state. Uninstallation of octave-forge
> packages does not work. Is this a bug?
>   
This is strange and I see no relationship between the octave-forge
packages and the fail of these commands.. Imagesc was rewritten after
the release of 3.0.0 to use the "cdatamapping" property of the handle
instead to do the scaling. Maybe that is the reason for your issues.. If
so I expect it to be fixed in 3.0.1.
> Other problems with colorbar persisting from the 2.9 are that the colour
> bar does not scale to the size of image after a sequence of commands like
>
> subplot(1,2,1)
> imagesc(randn(200))
> axis square
> colorbar
>   
Hum, yes that is a bug, but I don't see an easy way of handling it as
there is no means to get gnuplot to scale the colorbar itself and still
have control of its location, where as gnuplot itself controls the size
of the subplot.. All we can do is have some sort of empirically derived
formula to do the scaling.. Try the attached patch that also tries to do
the right thing if the aspect ratio is not automatic.

> or the command
>
> colorbar('east')
>
> produces colour bar overlapped with the image and behind it.
>   
That is what is supposed to happen for 'east'. Try instead

colorbar('eastoutside')

> Does someone knows the ways to fix (circumvent) the aforementioned problems?
> And, more generally, is there a way to produce publication quality
> graphics from Octave?
>   
I'd hope that gnuplot's quality is at a level for publication.. You can
always use something like

drawnow ("x11", "/dev/null", false,"output.gp")

then use the file "output.gp" with gnuplot directly to get the final
manipulation of the figure in exactly the manner you want it...

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

# HG changeset patch
# User David Bateman <address@hidden>
# Date 1208772643 -7200
# Node ID f327e58a0c47859bf478f3d5b7a513067c3008f4
# Parent  7ce582eb923e51dd4c47bee66c36d5a919f3f70e
Try to get the colorbar position right for manual aspect ratios as well

diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -51,7 +51,7 @@ function __go_draw_axes__ (h, plot_strea
 
     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 @@ function sym = __setup_sym_table__ ()
   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 @@ function [pos, orient, sz, origin, mirr]
     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
diff --git a/scripts/plot/colorbar.m b/scripts/plot/colorbar.m
--- a/scripts/plot/colorbar.m
+++ b/scripts/plot/colorbar.m
@@ -148,3 +148,92 @@ endfunction
 %! 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");
+
+

reply via email to

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