-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfgplot.m
95 lines (83 loc) · 2.32 KB
/
fgplot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function h=fgplot(A,xy,varargin)
% FGPLOT Fancy graph plot
%
% fgplot(A,xy) - basic fancy gplot
% fgplot(A,xy,f) - fancy gplot with labeled points
%
% fgplot(A,xy,'key',value,'key',value,...)
% fgplot(A,xy,f,'key',value,'key',value,...)
% provide optional arguments
% 'Background' - The background plot color, default=0.83*[1,1,1].
% use 'none' for white.
% 'LineWidth' - The graph edge linewidth, default=0.4
% 'Color' - The graph color, default=0.55*[1,1,1]
% 'Border'
% 'VertexSize'
% '
%
% David F. Gleich
% Sandia National Labs, 2011
% History
% -------
% :2011-05-17: Initial coding
% :2011-06-24: Added alpha blending
% :2011-10-22: Added options
% :2011-10-28: Added option for no alpha
p=inputParser;
p.addParamValue('Border',0.05,@isnumeric);
p.addParamValue('LineWidth',0.4,@isnumeric);
p.addParamValue('Alpha',0.1,@isnumeric);
p.addParamValue('Background',0.83*[1,1,1],@iscolor);
p.addParamValue('Color',0.55*[1,1,1],@iscolor);
p.addParamValue('MarkerSize',10,@isnumeric);
p.addParamValue('MarkerColor',[0.8,0,0],@iscolor);
p.addParamValue('Style','thin',...
@(x) any(validatestring(x,{'thin','thick'})));
p.parse(varargin{:});
opts = p.Results;
if strcmp(opts.Style,'thick')
opts.MarkerSize = 25;
opts.LineWidth = 1.25;
opts.Alpha = 0.5;
end
% Generate the graph
rehold = ishold;
[lx,ly]=gplot(A,xy);
%h=plot(lx,ly,'k-','LineWidth',graphlw);
if opts.Alpha < 1
h = aplot(lx,ly,'plotcolor',opts.Color,'alpha',opts.Alpha);
set(h,'LineWidth',opts.LineWidth);
else
h = plot(lx,ly,'-','Color',opts.Color,'LineWidth',opts.LineWidth);
end
set(gcf,'Color',opts.Background);
hold on;
axis off;
axis square;
if opts.Border>0
add_border(xy, opts.Background, opts.Border);
end
if opts.MarkerSize>0
hs=scatter(xy(:,1),xy(:,2),opts.MarkerSize);
set(hs,'MarkerFaceColor',opts.MarkerColor);
set(hs,'MarkerEdgeColor',opts.MarkerColor);
end
if ~rehold, hold off; end
function add_border(xy,bkgcolor, s)
% add points to get
xymin = min(xy);
xymax = max(xy);
xysize = xymax-xymin;
xy1 = xymin-s*xysize;
xy2 = xymax+s*xysize;
h = plot(xy1(1),xy1(2),'.'); set(h,'Color',bkgcolor);
h = plot(xy2(1),xy2(2),'.'); set(h,'Color',bkgcolor);
function rval=iscolor(x)
rval=true;
if numel(x)~=3
rval=false;
return
elseif any(x<0) || any(x>1)
rval=false;
return;
end