-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathplot_pattern_diagram_markers.m
117 lines (106 loc) · 3.95 KB
/
plot_pattern_diagram_markers.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function varargout = plot_pattern_diagram_markers(X,Y,option)
%PLOT_PATTERN_DIAGRAM_MARKERS Plots color markers on a pattern diagram.
%
% [HP, HT] = PLOT_PATTERN_DIAGRAM_MARKERS(X,Y,OPTION)
% Plots color markers on a target or Taylor diagram according their
% (X,Y) locations. The symbols and colors are chosen according to the
% selections made in the OPTION variable. Refer to the following
% functions for selecting the options:
% GET_TARGET_DIAGRAM_OPTIONS
% GET_TAYLOR_DIAGRAM_OPTIONS
%
% INPUTS:
% x : x-coordinates of markers
% y : y-coordinates of markers
% option : data structure containing option values. (Refer to
% *_DIAGRAM_OPTIONS functions for more information.)
% option.axismax : maximum for the X & Y values. Used to limit
% maximum distance from origin to display markers
% option.markerLabel : labels for markers
%
% OUTPUTS:
% hp: returns handles of plotted points
% ht: returns handles of the text legend of points
% Get axis limit
limit = option.axismax;
% Set face color transparency
alpha = option.alpha;
% Set marker size
fontSize = get(gcf,'DefaultAxesFontSize');
markerSize = option.markerSize;
% Define markers to use in pattern diagram
[markerSymbol, markerColor] = get_markers(X,option);
if strcmp(option.markerLegend,'on')
% Check that marker labels have been provided
if ~isfield(option,'markerLabel')
error('No markerLabel field in option data structure.');
elseif isempty(option.markerLabel)
error('No marker labels provided.');
end
% Plot markers of different color and shapes at data points
hp = []; markerLabel = [];
hMarker = []; lMarker = [];
ht = cell(1); % create an empty cell to return
for i=1:length(X)
if abs(X(i)) <= limit & abs(Y(i)) <= limit
h = plot(X(i),Y(i),markerSymbol(i),'MarkerFaceColor',markerColor(i,:), ...
'MarkerEdgeColor',markerColor(i,:), 'MarkerSize',markerSize, ...
'Linewidth',2.5);
hm = setMarkerColor(h,markerColor(i,:),alpha); % Apply transparency to marker
hp = [hp; h];
markerLabel = [markerLabel; option.markerLabel(:,i)];
hMarker = [hMarker; hm];
lMarker = [lMarker; markerColor(i,:)];
hold on;
end % if limit test
end %for loop
% Add legend
if length(markerLabel) == 0
warning('No markers within axis limit ranges.');
else
add_legend(markerLabel,option,lMarker,markerSize,fontSize,hp);
end
else
% Plot same kind of marker at data points
hp = []; ht = [];
for i=1:length(X)
if abs(X(i)) <= limit & abs(Y(i)) <= limit
% Plot marker
h = plot(X(i),Y(i),markerSymbol, ...
'MarkerSize',markerSize,'MarkerFaceColor',markerColor, ...
'MarkerEdgeColor',markerColor,'Linewidth',2.5);
hm = setMarkerColor(h,markerColor,alpha); % Apply transparency to marker
hp = [hp; h];
if isfield(option,'markerLabel') && isa(option.markerLabel,'cell')
% Label marker
xtextpos = double(X(i));
ytextpos = double(Y(i));
htext = text(xtextpos,ytextpos, ...
option.markerLabel(i), ...
'Color',option.markerLabelColor);
ht = [ht; htext];
end
hold on;
end % if limit test
end % markers loop
% Add legend if labels provided as map
if isfield(option,'markerLabel')
if isMap(option.markerLabel)
add_legend(option.markerLabel,option,[],markerSize,fontSize,hp);
end
if length(ht) > 0
set(ht,'verticalalignment','bottom','horizontalalignment','right', ...
'fontsize',fontSize)
end
end
end
% Output
switch nargout
case 1
varargout(1) = {hp};
case 2
varargout(1) = {hp};
varargout(2) = {ht};
end
hold on;
end %function plot_pattern_diagram_markers