changeset 10910:40cf7cc4ea62

Properly interpret plotboxaspectratio when 3D objects are viewed as 2D.
author Ben Abbott <bpabbott@mac.com>
date Tue, 24 Aug 2010 18:12:45 -0400
parents ac43a9df78d6
children da90c16fbe84
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/colorbar.m scripts/plot/private/__actual_axis_position__.m
diffstat 4 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,9 @@
+2010-08-24  Ben Abbott <bpabbott@mac.com>
+
+	* plot/private/__actual_axis_position__.m, plot/__go_draw_axes__.m:
+	Properly interpret plotboxaspectratio when 3D objects are viewed as 2D.
+	* /plot/colorbar.m: Add demo.
+
 2010-08-23  Jaroslav Hajek  <highegg@gmail.com>
 
 	* general/interp2.m: Don't use bicubic for consistency (can't handle
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __go_draw_axes__ (h, plot_stream, enhanced, mono, implicit_margin, bg_is_set)
+function __go_draw_axes__ (h, plot_stream, enhanced, mono, bg_is_set)
 
   if (nargin >= 4 && nargin <= 6)
 
@@ -51,18 +51,21 @@
     else
       pos = axis_obj.position;
     endif
-    pos(1:2) = pos(1:2) - implicit_margin .* [0.75, 0.5];
     if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
-      if (nd == 2)
+      if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
         x = [1, 1];
       else
         ## 3D plots need to be sized down to fit in the window.
         x = 1.0 ./ sqrt([2, 2.5]);
       endif
-      fprintf (plot_stream, "set tmargin screen %.15g;\n", pos(2)+pos(4)/2+x(2)*pos(4)/2);
-      fprintf (plot_stream, "set bmargin screen %.15g;\n", pos(2)+pos(4)/2-x(2)*pos(4)/2);
-      fprintf (plot_stream, "set lmargin screen %.15g;\n", pos(1)+pos(3)/2-x(1)*pos(3)/2);
-      fprintf (plot_stream, "set rmargin screen %.15g;\n", pos(1)+pos(3)/2+x(1)*pos(3)/2);
+      fprintf (plot_stream, "set tmargin screen %.15g;\n",
+               pos(2)+pos(4)/2+x(2)*pos(4)/2);
+      fprintf (plot_stream, "set bmargin screen %.15g;\n",
+               pos(2)+pos(4)/2-x(2)*pos(4)/2);
+      fprintf (plot_stream, "set lmargin screen %.15g;\n",
+               pos(1)+pos(3)/2-x(1)*pos(3)/2);
+      fprintf (plot_stream, "set rmargin screen %.15g;\n",
+               pos(1)+pos(3)/2+x(1)*pos(3)/2);
     else
       ## FIXME -- nothing should change for gnuplot 4.2.x.
       fprintf (plot_stream, "set tmargin 0;\n");
@@ -101,7 +104,8 @@
         fprintf (plot_stream, "set title \"%s\" %s %s",
                  undo_string_escapes (tt), fontspec,
                  __do_enhanced_option__ (enhanced, t));
-        if (nd == 3 && __gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
+        if (nd == 3
+            && __gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
           fprintf (plot_stream, " offset screen 0, screen %.3f;\n", pos(4)/5);
         else
           fprintf (plot_stream, ";\n");
--- a/scripts/plot/colorbar.m
+++ b/scripts/plot/colorbar.m
@@ -575,6 +575,13 @@
 
 %!demo
 %! clf
+%! pcolor (peaks (20))
+%! shading ("interp")
+%! axis ("tight", "square")
+%! colorbar ()
+
+%!demo
+%! clf
 %! plot([0, 2])
 %! colorbar ("east")
 %! axis equal
--- a/scripts/plot/private/__actual_axis_position__.m
+++ b/scripts/plot/private/__actual_axis_position__.m
@@ -31,13 +31,13 @@
 
   ## When using {rltb}margin, Gnuplot does not handle the specified
   ## aspect ratio properly, so handle it here.
-  if (__calc_dimensions__ (axis_obj) == 3)
+  if (__calc_dimensions__ (axis_obj) == 2 || all (mod (axis_obj.view, 90) == 0))
+    aspect_ratio_2d = axis_obj.plotboxaspectratio(1:2);
+  else
     ## FIXME -- this works for "axis square", but has not been
     ##          thoroughly tested for other aspect ratios.
     aspect_ratio_2d = [max(axis_obj.plotboxaspectratio(1:2)), ...
                            axis_obj.plotboxaspectratio(3)/sqrt(2)];
-  else
-    aspect_ratio_2d = axis_obj.plotboxaspectratio(1:2);
   endif
   orig_fig_units = get (axis_obj.parent, "units");
   orig_fig_position = get (axis_obj.parent, "position");