From: <par...@us...> - 2011-12-11 15:37:22
|
Revision: 9365 http://octave.svn.sourceforge.net/octave/?rev=9365&view=rev Author: paramaniac Date: 2011-12-11 15:37:14 +0000 (Sun, 11 Dec 2011) Log Message: ----------- control: rework axis limits of plotting Modified Paths: -------------- trunk/octave-forge/main/control/inst/bode.m Added Paths: ----------- trunk/octave-forge/main/control/inst/__plot_margin__.m Added: trunk/octave-forge/main/control/inst/__plot_margin__.m =================================================================== --- trunk/octave-forge/main/control/inst/__plot_margin__.m (rev 0) +++ trunk/octave-forge/main/control/inst/__plot_margin__.m 2011-12-11 15:37:14 UTC (rev 9365) @@ -0,0 +1,61 @@ +## Copyright (C) 1998, 2000, 2004, 2005, 2007 +## Auburn University. All rights reserved. +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __plot_margin__ (@var{axdata}) +## Determine axis limits for 2-D data (column vectors); leaves a 10% +## margin around the plots. +## Inserts margins of +/- 0.1 if data is one-dimensional +## (or a single point). +## +## @strong{Input} +## @table @var +## @item axdata +## @var{n} by 2 matrix of data [@var{x}, @var{y}]. +## @end table +## +## @strong{Output} +## @table @var +## @item axvec +## Vector of axis limits appropriate for call to @command{axis} function. +## @end table +## @end deftypefn + +function axvec = __plot_margin__ (axdata) + + ## compute axis limits + minv = axdata(1); + maxv = axdata(2); + delv = (maxv-minv)/2; # breadth of the plot + midv = (minv + maxv)/2; # midpoint of the plot + axmid = [midv, midv]; + axdel = [-0.1, 0.1]; # default plot width (if less than 2-d data) + if (delv == 0) + if (midv != 0) + axdel = [-0.1*midv, 0.1*midv]; + endif + else + ## they're at least one-dimensional + tolv = max(1e-8, 1e-8*abs(midv)); + if (abs (delv) >= tolv) + axdel = 1.1*[-delv,delv]; + endif + endif + axvec = axmid + axdel; + +endfunction Modified: trunk/octave-forge/main/control/inst/bode.m =================================================================== --- trunk/octave-forge/main/control/inst/bode.m 2011-12-11 15:04:33 UTC (rev 9364) +++ trunk/octave-forge/main/control/inst/bode.m 2011-12-11 15:37:14 UTC (rev 9365) @@ -64,12 +64,6 @@ if (! nargout) mag_db = 20 * log10 (mag); - wv = [min(w), max(w)]; - ax_vec_mag = __axis_limits__ ([reshape(w, [], 1), reshape(mag_db, [], 1)]); - ax_vec_mag(1:2) = wv; - ax_vec_pha = __axis_limits__ ([reshape(w, [], 1), reshape(pha, [], 1)]); - ax_vec_pha(1:2) = wv; - if (isct (sys)) xl_str = "Frequency [rad/s]"; else @@ -78,18 +72,16 @@ subplot (2, 1, 1) semilogx (w, mag_db) - ax = axis; - if (any (isinf (ax_vec_mag))) # catch case purely imaginary poles or zeros - ax_vec_mag(3:4) = ax(3:4); - endif - axis (ax_vec_mag) + axis ("tight") + ylim (__plot_margin__ (ylim)); grid ("on") title (["Bode Diagram of ", inputname(1)]) ylabel ("Magnitude [dB]") subplot (2, 1, 2) semilogx (w, pha) - axis (ax_vec_pha) + axis ("tight") + ylim (__plot_margin__ (ylim)); grid ("on") xlabel (xl_str) ylabel ("Phase [deg]") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |