Home > FMAToolbox > Plot > PlotTicks.m

PlotTicks

PURPOSE ^

PlotTicks - Plot ticks.

SYNOPSIS ^

function p = PlotTicks(xy,varargin)

DESCRIPTION ^

PlotTicks - Plot ticks.

  USAGE

    p = PlotTicks(x,y,<options>,<options2>)

    x              list of tick abscissae
    y              list of tick ordinates
    <options>      optional list of property-value pairs (see table below)
    <options2>     options for function <a href="matlab:help plot">plot</a>

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'direction'   direction: 'h' or 'v' (default = 'v')
     'size'        tick size ([] or default = best guess)
     'color'       either a single [R G B] color, or one per tick
    =========================================================================

  NOTE

    When a single list of coordinates is provided, e.g. PlotTicks(t), these
    are assumed to be abscissae or ordinates depending on 'direction', and
    the ticks are plotted centered on 0.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function p = PlotTicks(xy,varargin)
0002 
0003 %PlotTicks - Plot ticks.
0004 %
0005 %  USAGE
0006 %
0007 %    p = PlotTicks(x,y,<options>,<options2>)
0008 %
0009 %    x              list of tick abscissae
0010 %    y              list of tick ordinates
0011 %    <options>      optional list of property-value pairs (see table below)
0012 %    <options2>     options for function <a href="matlab:help plot">plot</a>
0013 %
0014 %    =========================================================================
0015 %     Properties    Values
0016 %    -------------------------------------------------------------------------
0017 %     'direction'   direction: 'h' or 'v' (default = 'v')
0018 %     'size'        tick size ([] or default = best guess)
0019 %     'color'       either a single [R G B] color, or one per tick
0020 %    =========================================================================
0021 %
0022 %  NOTE
0023 %
0024 %    When a single list of coordinates is provided, e.g. PlotTicks(t), these
0025 %    are assumed to be abscissae or ordinates depending on 'direction', and
0026 %    the ticks are plotted centered on 0.
0027 
0028 % Copyright (C) 2008-2014 by Michaƫl Zugaro
0029 %
0030 % This program is free software; you can redistribute it and/or modify
0031 % it under the terms of the GNU General Public License as published by
0032 % the Free Software Foundation; either version 3 of the License, or
0033 % (at your option) any later version.
0034 
0035 if nargin < 1,
0036      error('Incorrect number of parameters (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0037 end
0038 
0039 % Defaults
0040 direction = 'v';
0041 yx = 0;
0042 color = [];
0043 s = [];
0044 v = {};
0045 
0046 % Does parameter list include both x and y?
0047 both = false;
0048 if ~isempty(varargin) && isnumeric(varargin{1}),
0049     x = xy;
0050     y = varargin{1};
0051     varargin = {varargin{2:end}};
0052     both = true;
0053 end
0054 
0055 % Parse parameter list
0056 n = 1;
0057 for i = 1:2:length(varargin),
0058     if ~ischar(varargin{i}),
0059         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).']);
0060     end
0061     switch(lower(varargin{i})),
0062         case 'size',
0063             s = varargin{i+1};
0064             if ~isdscalar(s) && ~isdvector(s),
0065                 error('Incorrect value for property ''size'' (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0066             end
0067 
0068         case 'direction',
0069             direction = lower(varargin{i+1});
0070             if ~isastring(direction,'h','v'),
0071                 error('Incorrect value for property ''direction'' (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0072             end
0073 
0074         case 'color',
0075             color = varargin{i+1};
0076             if ~isdmatrix(color,'>=0','<=1') || size(color,2) ~= 3,
0077                 error('Incorrect value for property ''color'' (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0078             end
0079 
0080         otherwise,
0081             v = {varargin{i:end}};
0082             if ~isa(v,'cell'), v = {v}; end
0083             break;
0084     end
0085 end
0086 
0087 if ~both,
0088     if strcmp(direction,'v'),
0089         x = xy;
0090         y = yx;
0091     else
0092         x = yx;
0093         y = xy;
0094     end
0095 end
0096 
0097 % Check list lengths
0098 if ~isdvector(x) | ~isdvector(y) | (~isdscalar(x) & ~isdscalar(y) & any(size(x) ~= size(y))),
0099      error('Incorrect abscissae/ordinates (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0100 else
0101     if isscalar(x),
0102         x = x*ones(size(y));
0103     else
0104         x = x(:);
0105     end
0106     if isscalar(y),
0107         y = y*ones(size(x));
0108     else
0109         y = y(:);
0110     end
0111 end
0112 
0113 % Default size
0114 if isempty(s),
0115     if strcmp(direction,'v'),
0116         s = min(diff(unique(y)))*0.75;
0117     else
0118         s = min(diff(unique(x)))*0.75;
0119     end
0120     if isempty(s), s = 0.75; end
0121 end
0122 
0123 s = s(:);
0124 if length(s) == 1,
0125     s = repmat(s,length(x),1);
0126 elseif any(size(x) ~= size(s)),
0127      error('Inconsistent numbers of abscissae/ordinates and sizes (type ''help <a href="matlab:help PlotTicks">PlotTicks</a>'' for details).');
0128 end
0129 
0130 hold on;
0131 if strcmp(direction,'v'),
0132     if isempty(color),
0133         for i = 1:length(x),
0134             plot([x(i) x(i)],[y(i)-s(i)/2 y(i)+s(i)/2],v{:});
0135         end
0136     else
0137         if size(color,1) == 1, color = repmat(color,length(x),1); end
0138         for i = 1:length(x),
0139             plot([x(i) x(i)],[y(i)-s(i)/2 y(i)+s(i)/2],'color',color(i,:),v{:});
0140         end
0141     end
0142 else
0143     if isempty(color),
0144         for i = 1:length(x),
0145             plot([x(i)-s(i)/2 x(i)+s(i)/2],[y(i) y(i)],v{:});
0146         end
0147     else
0148         if size(color,1) == 1, color = repmat(color,length(x),1); end
0149         for i = 1:length(x),
0150             plot([x(i)-s(i)/2 x(i)+s(i)/2],[y(i) y(i)],'color',color(i,:),v{:});
0151         end
0152     end
0153 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005