# HG changeset patch # User Rik # Date 1381254908 25200 # Node ID 4975ccb0a9169c08fac1127e141d2bfbae8ec41f # Parent dcbab6f3e7270e48bfb47cfbbf914290c29c1df1 pcolor.m: Calculate and apply axis limits for better plot appearance. * scripts/plot/draw/pcolor.m: Look for integer x,y values and apply tight axis limits if found. This requires deciphering whether x is a vector, meshgrid matrix, or ndgrid matrix. diff -r dcbab6f3e727 -r 4975ccb0a916 scripts/plot/draw/pcolor.m --- a/scripts/plot/draw/pcolor.m Tue Oct 08 08:50:06 2013 -0700 +++ b/scripts/plot/draw/pcolor.m Tue Oct 08 10:55:08 2013 -0700 @@ -63,7 +63,8 @@ if (nargin == 1) c = varargin{1}; [nr, nc] = size (c); - [x, y] = meshgrid (1:nc, 1:nr); + x = 1:nc; + y = 1:nr; z = zeros (nr, nc); elseif (nargin == 3) x = varargin{1}; @@ -86,12 +87,34 @@ if (! ishold ()) set (hax, "view", [0, 90], "box", "on"); ## FIXME: Maybe this should be in the general axis limit setting routine? - ## When values are integers, want to use tight limits. - if (all (x(:) == fix (x(:)))) - xlim ([min(x(:)), max(x(:))]); + ## When values are integers (such as from meshgrid), we want to + ## use tight limits for pcolor, mesh, surf, etc. Situation is + ## complicated immensely by vector or matrix input and meshgrid() + ## or ndgrid() format. + meshgrid_fmt = true; + if (isvector (x)) + xrng = x(isfinite (x)); + else + xrng = x(1, isfinite (x(1,:))); # meshgrid format (default) + if (all (xrng == xrng(1))) + xrng = x(isfinite (x(:,1)), 1); # ndgrid format + meshgrid_fmt = false; + endif endif - if (all (y(:) == fix (y(:)))) - ylim ([min(y(:)), max(y(:))]); + if (isvector (y)) + yrng = y(isfinite (y)); + else + if (meshgrid_fmt) + yrng = y(isfinite (y(:,1)), 1); + else + yrng = y(1, isfinite (y(1,:))); + endif + endif + if (all (xrng == fix (xrng))) + xlim ([min(xrng), max(xrng)]); + endif + if (all (yrng == fix (yrng))) + ylim ([min(yrng), max(yrng)]); endif endif