Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sldrawgraph
Home > sltoolbox > visualize > sldrawgraph.m

sldrawgraph

PURPOSE ^

SLDRAWGRAPH Draws a graph

SYNOPSIS ^

function h = sldrawgraph(G, X, Xt, ppedges, ppsn, pptn)

DESCRIPTION ^

SLDRAWGRAPH Draws a graph

 $ Syntax $
   - sldrawgraph(G, X)
   - sldrawgraph(G, X, Xt)
   - sldrawgraph(G, X, [], ppedges)
   - sldrawgraph(G, X, [], ppedges, ppsn)
   - sldrawgraph(G, X, Xt, ppedges)
   - sldrawgraph(G, X, Xt, ppedges, pptn)
   - h = sldrawgraph(...)

 $ Arguments $
   - G:        The graph in any acceptable form
   - X:        The sample matrix of (source) nodes (2xn or 3xn)
   - Xt:       The sample matrix of (target) nodes (2xn or 3xn)
   - ppedges:  The cell array of parameters for plotting graph edges
   - ppsn:     The cell array of parameters for plotting source nodes
   - pptn:     The cell array of parameters for plotting target nodes
   - h:        The vector of handles to all plotted objects

 $ Description $
   - sldrawgraph(G, X) draws a graph with the coordinates of the 
     graph nodes given in X (a 2 x n matrix for 2D points or 3 x n
     matrix for 3D points), using default plotting parameters.

   - sldrawgraph(G, X, Xt) draws a bigraph using default plotting
     parameters.

   - sldrawgraph(G, X, [], ppedges) draws a graph using the specified
     parameters to draw edges.

   - sldrawgraph(G, X, [], ppedges, ppsn) draws a graph using the 
     specified parameters to draw edges and nodes.

   - sldrawgraph(G, X, Xt, ppedges) draws a bigraph using the specified
     parameters to draw edges.

   - sldrawgraph(G, X, Xt, ppedges, ppsn, pptn) draws a bigraph using the 
     specified parameters to draw edges and nodes.

   - h = sldrawgraph(...) returns the handles to the plotted objects.

 $ History $
   - Created by Dahua Lin, on Sep 11st, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sledgeset SLEDGESET Construct the edge set representation of a graph
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
  • slpruneedgeset SLPRUNEEDGESET Prunes the edge set
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:

SOURCE CODE ^

0001 function h = sldrawgraph(G, X, Xt, ppedges, ppsn, pptn)
0002 %SLDRAWGRAPH Draws a graph
0003 %
0004 % $ Syntax $
0005 %   - sldrawgraph(G, X)
0006 %   - sldrawgraph(G, X, Xt)
0007 %   - sldrawgraph(G, X, [], ppedges)
0008 %   - sldrawgraph(G, X, [], ppedges, ppsn)
0009 %   - sldrawgraph(G, X, Xt, ppedges)
0010 %   - sldrawgraph(G, X, Xt, ppedges, pptn)
0011 %   - h = sldrawgraph(...)
0012 %
0013 % $ Arguments $
0014 %   - G:        The graph in any acceptable form
0015 %   - X:        The sample matrix of (source) nodes (2xn or 3xn)
0016 %   - Xt:       The sample matrix of (target) nodes (2xn or 3xn)
0017 %   - ppedges:  The cell array of parameters for plotting graph edges
0018 %   - ppsn:     The cell array of parameters for plotting source nodes
0019 %   - pptn:     The cell array of parameters for plotting target nodes
0020 %   - h:        The vector of handles to all plotted objects
0021 %
0022 % $ Description $
0023 %   - sldrawgraph(G, X) draws a graph with the coordinates of the
0024 %     graph nodes given in X (a 2 x n matrix for 2D points or 3 x n
0025 %     matrix for 3D points), using default plotting parameters.
0026 %
0027 %   - sldrawgraph(G, X, Xt) draws a bigraph using default plotting
0028 %     parameters.
0029 %
0030 %   - sldrawgraph(G, X, [], ppedges) draws a graph using the specified
0031 %     parameters to draw edges.
0032 %
0033 %   - sldrawgraph(G, X, [], ppedges, ppsn) draws a graph using the
0034 %     specified parameters to draw edges and nodes.
0035 %
0036 %   - sldrawgraph(G, X, Xt, ppedges) draws a bigraph using the specified
0037 %     parameters to draw edges.
0038 %
0039 %   - sldrawgraph(G, X, Xt, ppedges, ppsn, pptn) draws a bigraph using the
0040 %     specified parameters to draw edges and nodes.
0041 %
0042 %   - h = sldrawgraph(...) returns the handles to the plotted objects.
0043 %
0044 % $ History $
0045 %   - Created by Dahua Lin, on Sep 11st, 2006
0046 %
0047 
0048 %% parse and verify input arguments
0049 
0050 if nargin < 2
0051     raise_lackinput('sldrawgraph', 2);
0052 end
0053 
0054 EG = sledgeset(G, 'off');
0055 gi = slgraphinfo(EG);
0056 n = gi.n;
0057 nt = gi.nt;
0058 
0059 d = size(X, 1);
0060 if ~isnumeric(X) || ndims(X) ~= 2 || (d ~= 2 && d ~= 3)
0061     error('sltoolbox:invalidarg', ...
0062         'The X should be a 2D numeric matrix, and should have 2 or 3 rows.');
0063 end
0064 
0065 if nargin < 3 || isempty(Xt)
0066     Xt = X;
0067     bi = false;
0068 else
0069     if ~isnumeric(Xt) || ndims(Xt) ~= 2
0070         error('sltoolbox:invalidarg', ...
0071             'The X should be a 2D numeric matrix, and should have 2 or 3 rows.');
0072     end
0073     if size(Xt, 1) ~= d
0074         error('sltoolbox:sizmismatch', ...
0075             'The sample dimensions in Xt is not the same as X');
0076     end
0077     bi = true;
0078 end
0079 
0080 if size(X, 2) ~= n || size(Xt, 2) ~= nt
0081     error('sltoolbox:sizmismatch', ...
0082         'The size of graph is not consistent with the sample numbers');
0083 end
0084 
0085 
0086 if nargin < 4 || isempty(ppedges)
0087     ppedges = {};
0088 end
0089 
0090 if nargin < 5 || isempty(ppsn)
0091     ppsn = {};
0092 end
0093 
0094 if nargin < 6 || isempty(pptn)
0095     pptn = ppsn;
0096 end
0097 
0098 if nargout >= 1
0099     output_h = true;
0100 else
0101     output_h = false;
0102 end
0103 
0104 %% Prepare Data for plotting
0105 
0106 % produce pruned NaN-separated coordinate list
0107 
0108 edges = EG.edges;
0109 edges = slpruneedgeset(n, nt, edges);
0110 
0111 I = edges(:,1);
0112 J = edges(:,2);
0113 nedges = length(I);
0114 
0115 xc = [X(1, I); Xt(1, J); NaN(1, nedges)];
0116 xc = xc(:);
0117 yc = [X(2, I); Xt(2, J); NaN(1, nedges)];
0118 yc = yc(:);
0119 if d == 3
0120     zc = [X(3, I); Xt(3, J); NaN(1, nedges)];
0121     zc = zc(:);
0122 end
0123 
0124 %% plot edges
0125 
0126 % plot the edges
0127 if d == 2
0128     ch = plot(xc, yc, ppedges{:});
0129 else
0130     ch = plot3(xc, yc, zc, ppedges{:});
0131 end
0132 if output_h
0133     h = ch;
0134 end
0135 clear xc yc zc;
0136 
0137 %% plot source nodes
0138 
0139 if ~isempty(ppsn)
0140     ppsn = [ppsn, {'LineStyle', 'none'}];
0141     hold on;
0142     if d == 2
0143         ch = plot(X(1,:), X(2,:), ppsn{:});
0144     else
0145         ch = plot3(X(1,:), X(2,:), X(3,:), ppsn{:});
0146     end
0147     if output_h
0148         h = [h; ch];
0149     end
0150 end
0151 
0152 %% plot target nodes
0153 
0154 if bi && ~isempty(pptn)
0155     pptn = [pptn, {'LineStyle', 'none'}];
0156     hold on;
0157     if d == 2
0158         ch = plot(Xt(1,:), Xt(2,:), pptn{:});
0159     else
0160         ch = plot3(Xt(1,:), Xt(2,:), Xt(3,:), pptn{:});
0161     end
0162     if output_h
0163         h = [h; ch];
0164     end
0165 end
0166 
0167

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com