Home > matgraph > @graph > draw.m

draw

PURPOSE ^

draw(g) --- draw g in a figure window

SYNOPSIS ^

function draw(g,line_style)

DESCRIPTION ^

 draw(g) --- draw g in a figure window
 draw(g,line_style) --- lines have given line_style
 see also ndraw, ldraw, and cdraw

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function draw(g,line_style)
0002 % draw(g) --- draw g in a figure window
0003 % draw(g,line_style) --- lines have given line_style
0004 % see also ndraw, ldraw, and cdraw
0005   
0006 % edit these to change the colors
0007 edge_color = 'b';
0008 vertex_color = 'r';
0009 vertex_fill = 'w';
0010 r = 0.15;
0011   
0012 n = nv(g);
0013   
0014 if nargin < 2
0015     line_style='-';
0016 end
0017 
0018 
0019 if ~hasxy(g)
0020     embed(g);
0021 end
0022 
0023 xy = getxy(g);
0024 
0025 % first draw the edges
0026 
0027 elist = edges(g);
0028 for j=1:ne(g)
0029     u = elist(j,1);
0030     v = elist(j,2);
0031     x = xy([u,v],1);
0032     y = xy([u,v],2);
0033     line(x,y,'Color', edge_color,'LineStyle',line_style);
0034 end
0035 
0036 
0037 % now draw the vertices
0038   
0039 for v=1:n
0040     x = xy(v,1);
0041     y = xy(v,2);
0042     rectangle('Position', [x-r/2, y-r/2, r, r],...
0043               'Curvature', [1 1], ...
0044               'EdgeColor', vertex_color, ...
0045               'FaceColor', vertex_fill);    
0046 end
0047 
0048 
0049 
0050 axis equal
0051 axis off

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003