-
Notifications
You must be signed in to change notification settings - Fork 0
/
legendlinestyles.m
62 lines (60 loc) · 2.16 KB
/
legendlinestyles.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
function legendlinestyles(h,markers,linestyles,linecolors)
% legendlinestyles(h,markers,linestyles,linecolors)
%==========================================================================
% Change the linestyles in an existing plot legend.
%
% Input: Handle to an existing legend object, h
% (optional) Cell array with the new markers, markers
% (optional) Cell array with the new linestyles, linestyles
% (optional) Cell array with the new line and marker colors
%
% If you do not want to change a markerstyle or linestyle, supply an empty
% array {}. See examples below.
%
% If the 'linestyles' arument is ommitted, the original lines are left
% unchanged. Note, that no lines in the actual plot are affected. If emtpy,
% {}, the styles are left unchanged but the colors are changed according to
% the fourth argument.
%
% Output: None
%
%
% Examples on how to use (see also accompanying file
% legendlinestyles_test.m):
%
% legendlinestyles(h, markers);
% legendlinestyles(h, markers,linestyles);
% legendlinestyles(h, markers,linestyles,linecolors);
% legendlinestyles(h, markers,{},linecolors);
% legendlinestyles(h, {},linestyles,linecolors);
% legendlinestyles(h, {},{},linecolors);
%
%==========================================================================
% Version: 1.0
% Created: October 3, 2008, by Johan E. Carlson
% Last modified: May 12, 2009, by Johan E. Carlson
%==========================================================================
lines = findobj(get(h,'children'),'type','line');
m = 1;
for k = length(lines):-2:1,
if ~isempty(markers),
set(lines(k-1),'marker',char(markers{m}));
end
if (nargin >= 3) && (~isempty(linestyles)),
set(lines(k),'linestyle',char(linestyles{m}));
end
if nargin == 4,
if ischar(linecolors{m})==1,
set(lines(k),'color',char(linecolors{m}));
if ~isempty(markers),
set(lines(k-1),'MarkerEdgeColor',char(linecolors{m}));
end
else
set(lines(k),'color',linecolors{m});
if ~isempty(markers),
set(lines(k-1),'MarkerEdgeColor',linecolors{m});
end
end
end
m = m+1;
end