⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pplot.m

📁 物流分析工具包。Facility location: Continuous minisum facility location, alternate location-allocation (ALA)
💻 M
📖 第 1 页 / 共 2 页
字号:
function h = pplot(varargin)
%PPLOT Projection plot.
%        h = pplot('proj',...) % Current and subsequent plots w/ projection
%          = pplot(XY)         % Plot lines and points
%          = pplot(XY,LineSpec)       
%          = pplot(XY,LineSpec,'PropName',PropValue,...)
%          = pplot(XY,Labels,'PropName',PropValue,...) % Label points XY
%          = pplot(XY,'NumNode',...)                   % Number nodes
%          = pplot(IJ,XY,...)  % Plot graph
%          = pplot(IJ,Labels,XY,...)                   % Label arcs IJ
%          = pplot(rte,XY,...) % Plot routes
%          = pplot(rte,Labels,XY,...)                  % Label routes 'rte'
%          = pplot([IJ | rte],XY,Labels,...)           % Best-fit labels
%          = pplot(border,...) % Border offset percentage for XLim and YLim
%          = pplot('proj')     % Create new figure & axes with projection
%          = pplot             % Create without projection
%   'proj' = initialize current axes so that current and subsequent plots 
%            are projected using PROJ; if axes not initialized, then PPLOT 
%            plots data  unprojected (axes initialized by setting Tag 
%            property to 'proj')
%       XY = m x 2 matrix of m 2-D points, which, if projected, should be
%            longitude-latitude pairs (in decimal degrees)
%       IJ = n-row matrix arc list [i j] of arc heads and tails
%      rte = cell array of route vectors, rte = {[rte1],[rte2],...}
%            (label arcs of single-route and centroids of multiple routes)
% LineSpec = character string to display line object (see PLOT for options)
%   Labels = cell array of strings
%          = num2cell(1:m), if numbering XY
%          = num2cell(IJD(:,3)), if labeling arc costs in n x 3 matrix IJD
%          = cellstr(chararray), if using rows of character array as labels
% PropName = any line or text object property name
%PropValue = corresponding line object property value
%            (note: a structure or cell arrays can also be used for 
%            property name-value pairs (see SET for details))
%   border = nonnegative scalar offset percentage for point/arc border, 
%            where offset is percentage of max X,Y extent (only increases 
%            XLim,YLim to MaxXYLim, which can be set as the field of a 
%            structure stored in the "UserData" of the current axes (see 
%            MAKEMAP))
%          = 0 (default, with projection), no offset
%          = 0.2 (default, no projection), 20% offset
%        h = handle of line object created, or, if labels, vector of text
%            object handles created, or, if PPLOT('proj'), handle of axes
%
% Examples:
% XY = [2 2; 3 1; 4 3; 1 4];                  % Points
% pplot(XY,'r.')
% pplot(XY,num2cell(1:4))
%
% % Names of North Carolina cities
% [Name,XY] = nccity;
% makemap(XY)
% pplot(XY,'r.')
% pplot(XY,Name)
%
% IJ = [1 2; 1 3; 1 4];                       % Arc List
% h1 = pplot(IJ,XY,'g-');
% IJlab = {'(1,2)','(1,3)','(1,4)'};
% h2 = pplot(IJ,IJlab,XY);
% delete([h1; h2])
%
% rte = {[1 4 3 2 1]};                        % Route Vector
% h3 = pplot(rte,XY,'g-');
% rtelab = {'(1,4)','(4,3)','(3,2)','(2,1)'};
% h4 = pplot(rte,rtelab,XY);
% set(h3,'color','b')
%
% If current figure does not exist, then new figure created with 
% DOUBLEBUFFER ON and MATLOGMENU called. If current axes does not exist, 
% then new axes created with HOLD ON, AXIS EQUAL, and BOX ON.
%
% If IJ or rte not specified for labeling points, then the Delaunay
% triangulation of the points are used to fit the labels. Edges greater
% than two times the shortest edge incident on each point are not used.

% Copyright (c) 1994-2006 by Michael G. Kay
% Matlog Version 9 13-Jan-2006 (http://www.ie.ncsu.edu/kay/matlog)

% Input Error Checking ****************************************************
[projstr,XY,IJ,rte,LineSpec,Labels,arg1,arg2,arg3] = deal([]);
border = [];
Prop = {};
[PtLab,ArcLab,MultiRteLab,SingleRteLab,BFPtLab] = deal(false);

if nargin > 0 && ischar(varargin{1})
   projstr = lower(varargin{1}); 
   varargin = varargin(2:end);
elseif nargin > 0 && isreal(varargin{1}) && length(varargin{1}(:)) == 1
   border = varargin{1};  
   varargin = varargin(2:end);
end
nvarargin = length(varargin);
if nvarargin > 3, Prop = varargin(4:end); end
if nvarargin > 2, arg3 = varargin{3}; end
if nvarargin > 1, arg2 = varargin{2}; end
if nvarargin > 0, arg1 = varargin{1}; end

if isnumeric(arg1)
   if isempty(arg2)
      XY = arg1;
   else
      if ischar(arg2)
         XY = arg1; LineSpec = arg2;
         if nvarargin > 2, Prop = varargin(3:end); end
      elseif isnumeric(arg2)
         IJ = arg1; XY = arg2;
         if isempty(IJ), if nargout > 0, h = []; end, return, end
         if ~isempty(arg3)
            if ischar(arg3)
               LineSpec = arg3;
            elseif iscell(arg3)
               BFPtLab = true;  % BFPtLab = true;
               Labels = arg3;
            else
               Prop = varargin(3:end);
            end
         end
      elseif iscell(arg2)
         if ~isempty(arg3) && isnumeric(arg3)
            IJ = arg1; Labels = arg2; XY = arg3;
            if isempty(IJ), if nargout > 0, h = []; end, return, end
            ArcLab = true;  % ArcLab = true;
         else
            XY = arg1; Labels = arg2; PtLab = true;  % PtLab = true;
            if nvarargin > 2, Prop = varargin(3:end); end
         end
      end
   end
elseif iscell(arg1)
   rte = arg1;
   if isnumeric(arg2)
      XY = arg2;
      if ~isempty(arg3)
         if ischar(arg3)
            LineSpec = arg3;
         elseif iscell(arg3)
            BFPtLab = true;  % BFPtLab = true;
            Labels = arg3;
         else
            Prop = varargin(3:end);
         end
      end
   elseif iscell(arg2)
      if length(arg1) > 1
         MultiRteLab = true;  % MultiRteLab = true;
      else
         SingleRteLab = true;  % SingleRteLab = true;
      end
      Labels = arg2; XY = arg3;
   else
      error('Unknown input argument combination.')
   end
else
   error('Unknown input argument combination.')
end

if isempty(LineSpec), LineSpec = ''; end
[m,cXY] = size(XY);
[n,cIJ] = size(IJ);

if ~isempty(projstr) && ~strcmpi(projstr,'proj')
   error('First argument string not "proj".')
elseif ~isempty(border) && (~isfinite(border) || border < 0)
   error('"border" must be a nonnegative scalar.')
elseif ~isempty(border) && nvarargin < 1
   error('Points or arcs must be specified together with "border".')
elseif ~isempty(border) && ~isempty(Labels)
   error('"border" cannot be specified for Labels.')
elseif nvarargin > 0 && (isempty(XY) || cXY ~= 2 || ~isnumeric(XY))
   error('XY not a valid two-column matrix.')
elseif length(LineSpec(:)) > 4 && ~strcmpi('NumNode',LineSpec)
   error('LineSpec must be a valid character string (see PLOT).')
elseif strcmpi('NumNode',LineSpec) && m > 99
   error('Maximum of 99 nodes with NumNode option.')
elseif strcmpi('NumNode',LineSpec) && nargout > 0
   error('No output arguments with NumNode option.')
elseif ~isempty(IJ) && (cIJ < 2 || min(min(abs(IJ(:,[1 2])))) < 1 || ...
      max(max(abs(IJ(:,[1 2])))) > m || cIJ > 3)
   error('IJ not a valid arc list.')
elseif ~isempty(rte) && (~all(all(cellfun('isreal',rte))) || ...
      any(cellfun('prodofsize',rte) ~= cellfun('length',rte)) || ...
      min([rte{:}]) < 1 || max([rte{:}]) > m)
   error('"rte" not a valid route vector or cell array.')
elseif ~isempty(Labels) && (~all(cellfun('isreal',Labels)) || ...
      any(cellfun('length',Labels) ~= cellfun('prodofsize',Labels)))
   error('Labels must be a cell array of strings.')
elseif (PtLab || BFPtLab) && length(Labels(:)) ~= m
   error('Node Labels must be a m-element cell array.')
elseif ArcLab && length(Labels(:)) ~= n
   error('Arc Labels must be a n-element cell array.')
elseif SingleRteLab && length(Labels(:)) ~= length(rte{:}) - 1
   error('Route Labels must be a (|rte| - 1)-element cell array.')
elseif MultiRteLab && length(Labels(:)) ~= length(rte(:))
   error('Route Labels must be a |rte|-element cell array.')
end
% End (Input Error Checking) **********************************************

if strcmpi('NumNode',LineSpec)
   LineSpec = 'o';
   pplot(XY,LineSpec,'MarkerSize',12,'MarkerFaceColor','w',Prop{:});
   pplot(XY,num2cell(1:size(XY,1)),...
      'HorizontalAlignment','center','VerticalAlignment','middle');
   return  % Can't save handles from each call b/c causes error
end

if ~isempty(IJ), IJ = abs(IJ(:,[1 2])); end  % Ignore arc dir. and cost

if nvarargin == 0 || isempty(findobj('Type','figure'))  % New figure
   figure, set(gcf,'DoubleBuffer','on','Tag','Matlog Figure'), matlogmenu
end
if nvarargin == 0 || isempty(findobj('Type','axes'))
   gca; hold on, box on
   if m ~= 1, axis equal, end   % Single point corrupts axis labels 
   s.LastLineTag = [];
   s.MaxXYLim = [];
   set(gca,'UserData',s)
end

if ~isempty(projstr)
   if all(~strcmpi(get(gca,'Tag'),{'','proj'}))
      error('Tag string of current axes not empty or equal to "proj".')
   elseif strcmp(get(gca,'Tag'),'')
      set(gca,'Tag','proj')
   end
end

if nvarargin == 0, if nargout > 0, h = gca; end, return, end

if isempty(Labels)
   if ~isempty(IJ)
      X = XY(:,1); X = X(IJ); if n < 2, X = X'; end, X = [X repmat(NaN,n,1)]';
      Y = XY(:,2); Y = Y(IJ); if n < 2, Y = Y'; end, Y = [Y repmat(NaN,n,1)]';
      XY = [X(:) Y(:)];
   elseif ~isempty(rte)
      XYin = XY;
      XY = [];
      for i = 1:length(rte), XY = [XY; XYin([rte{i}],:); NaN NaN]; end
   end
end

if strcmp(get(gca,'Tag'),'proj')
   XY = proj(normlonlat(XY));
end

if isempty(Labels)  % Points and Arcs
   hout = plot(XY(:,1),XY(:,2),LineSpec,Prop{:});  % Call to PLOT

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -