# HG changeset patch # User Ben Abbott # Date 1282687965 14400 # Node ID 40cf7cc4ea624f35d5b4ab82facc6ae93a1fa32e # Parent ac43a9df78d63e0a89b4ad2bb86c221c2193bc7e Properly interpret plotboxaspectratio when 3D objects are viewed as 2D. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2010-08-24 Ben Abbott + + * 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 * general/interp2.m: Don't use bicubic for consistency (can't handle 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 @@ -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"); diff --git a/scripts/plot/colorbar.m b/scripts/plot/colorbar.m --- 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 diff --git a/scripts/plot/private/__actual_axis_position__.m b/scripts/plot/private/__actual_axis_position__.m --- 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");