Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/iplotyy.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % IPLOT provides an intelligent plotting tool for LTPDA. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: IPLOT provides an intelligent plotting tool for LTPDA. | |
5 % | |
6 % CALL: hfig = iplotyy (a1,a2,pl) | |
7 % [hfig, hax] = iplotyy (a1,a2,pl) | |
8 % [hfig, hax, hli] = iplotyy (a1,a2,pl) | |
9 % | |
10 % INPUTS: pl - a parameter list | |
11 % a1 - input analysis object for left y-axis | |
12 % a2 - input analysis object for right y-axis | |
13 % | |
14 % NOTE: the two input AOs must be the same data type. | |
15 % | |
16 % OUTPUTS: hfig - handles to figures | |
17 % hax - handles to axes | |
18 % hli - handles to lines | |
19 % | |
20 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'iplotyy')">Parameters Description</a> | |
21 % | |
22 % VERSION: $Id: iplotyy.m,v 1.14 2011/04/08 08:56:15 hewitson Exp $ | |
23 % | |
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
25 | |
26 function varargout = iplotyy(varargin) | |
27 | |
28 import utils.const.* | |
29 | |
30 %% Check if this is a call for parameters | |
31 if utils.helper.isinfocall(varargin{:}) | |
32 varargout{1} = getInfo(varargin{3}); | |
33 return | |
34 end | |
35 | |
36 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
37 | |
38 % Collect input variable names | |
39 in_names = cell(size(varargin)); | |
40 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
41 | |
42 % Check inputs | |
43 if nargin ~= 2 && nargin ~= 3 | |
44 error('### Incorrect inputs'); | |
45 end | |
46 | |
47 % Collect arrays | |
48 if nargin >= 2 | |
49 a1 = varargin{1}; | |
50 a2 = varargin{2}; | |
51 end | |
52 if ~isa(a1, 'ao') || ~isa(a2, 'ao') | |
53 error('### Please input two AOs followed by plists'); | |
54 end | |
55 | |
56 % Collect plists | |
57 if nargin >= 3 | |
58 pl = parse(varargin{3:end}, getDefaultPlist); | |
59 else | |
60 pl = getDefaultPlist; | |
61 end | |
62 | |
63 % Check size of input arrays | |
64 if numel(a1) ~= numel(a2) || numel(a1) ~= 1 | |
65 error('### Input two AOs.'); | |
66 end | |
67 | |
68 % get data type of a1 | |
69 dtype1 = class(a1.data); | |
70 % get data type of a2 | |
71 dtype2 = class(a2.data); | |
72 % check two arrays | |
73 if ~strcmp(dtype1, dtype2) | |
74 error('### The two input AOs should contain the same data type.'); | |
75 end | |
76 | |
77 dtype = dtype1; | |
78 | |
79 %% Now plot all the objects on separate figures | |
80 | |
81 switch dtype | |
82 case 'fsdata' | |
83 [hfig, hax, hli] = xy_plot(a1,a2,pl); | |
84 case 'tsdata' | |
85 [hfig, hax, hli] = xy_plot(a1,a2,pl); | |
86 case 'cdata' | |
87 error('### Currently unsupported'); | |
88 case 'xydata' | |
89 [hfig, hax, hli] = xy_plot(a1,a2,pl); | |
90 otherwise | |
91 error('### Unsupported data type: %s', dtype); | |
92 end | |
93 | |
94 %% Deal with outputs | |
95 if nargout == 1 | |
96 varargout{1} = hfig; | |
97 end | |
98 if nargout == 2 | |
99 varargout{1} = hfig; | |
100 varargout{2} = hax; | |
101 end | |
102 if nargout == 3 | |
103 varargout{1} = hfig; | |
104 varargout{2} = hax; | |
105 varargout{3} = hli; | |
106 end | |
107 | |
108 if nargout > 3 | |
109 error('### Incorrect number of outputs'); | |
110 end | |
111 | |
112 end | |
113 | |
114 %-------------------------------------------------------------------------- | |
115 % XY plot | |
116 %-------------------------------------------------------------------------- | |
117 function [hf, ha, hl] = xy_plot(a1,a2,pl) | |
118 | |
119 switch class(a1.data) | |
120 case 'fsdata' | |
121 pl = parse(pl, getDefaultPlist('Frequency-series plot')); | |
122 XLabelString = 'Frequency'; | |
123 x1 = a1.data.getX; | |
124 y1 = a1.data.getY; | |
125 x2 = a2.data.getX; | |
126 y2 = a2.data.getY; | |
127 % Title string | |
128 titleString = ''; | |
129 case 'tsdata' | |
130 pl = parse(pl, getDefaultPlist('Time-series plot')); | |
131 XLabelString = 'Time'; | |
132 % Collect T0s | |
133 T0(1) = inf; | |
134 if a1.data.t0.utc_epoch_milli/1000 < T0(1) | |
135 T0(1) = floor(a1.data.t0.utc_epoch_milli/1000); | |
136 end | |
137 T0(2) = inf; | |
138 if a2.data.t0.utc_epoch_milli/1000 < T0(2) | |
139 T0(2) = floor(a2.data.t0.utc_epoch_milli/1000); | |
140 end | |
141 | |
142 % deal with time-offsets | |
143 toff(1) = a1.data.t0.utc_epoch_milli/1000 - T0(1); | |
144 toff(2) = a2.data.t0.utc_epoch_milli/1000 - T0(1); | |
145 torigin(1) = time(T0(1)); | |
146 torigin(2) = time(T0(2)); | |
147 % need t0 offset for this time-series | |
148 x1 = a1.data.getX + toff(1); | |
149 y1 = a1.data.getY; | |
150 x2 = a2.data.getX + toff(2); | |
151 y2 = a2.data.getY; | |
152 % Title string | |
153 titleString = sprintf('Time origin: %s', char(torigin(1))); | |
154 case 'xydata' | |
155 pl = parse(pl, getDefaultPlist('X-Y plot')); | |
156 XLabelString = 'X'; | |
157 x1 = a1.data.getX; | |
158 y1 = a1.data.getY; | |
159 x2 = a2.data.getX; | |
160 y2 = a2.data.getY; | |
161 % Title string | |
162 titleString = ''; | |
163 end | |
164 | |
165 % Parameters | |
166 colL = find(pl, 'LeftColor'); | |
167 colR = find(pl, 'RightColor'); | |
168 styleL = find(pl, 'LeftLineStyle'); | |
169 styleR = find(pl, 'RightLineStyle'); | |
170 yscaleL = find(pl, 'LeftYScale'); | |
171 xscaleL = find(pl, 'LeftXScale'); | |
172 yscaleR = find(pl, 'RightYScale'); | |
173 xscaleR = find(pl, 'RightXScale'); | |
174 | |
175 pltfcn = 'plot'; | |
176 if strcmp(xscaleL, 'log') && strcmp(xscaleR, 'log') && ... | |
177 strcmp(yscaleL, 'log') && strcmp(yscaleR, 'log') | |
178 pltfcn = 'loglog'; | |
179 end | |
180 if strcmp(xscaleL, 'lin') && strcmp(xscaleR, 'lin') && ... | |
181 strcmp(yscaleL, 'log') && strcmp(yscaleR, 'log') | |
182 pltfcn = 'semilogy'; | |
183 end | |
184 if strcmp(xscaleL, 'log') && strcmp(xscaleR, 'log') && ... | |
185 strcmp(yscaleL, 'lin') && strcmp(yscaleR, 'lin') | |
186 pltfcn = 'semilogx'; | |
187 end | |
188 | |
189 % Make a new figure | |
190 hf = figure; | |
191 | |
192 % Plot | |
193 [ha,H1,H2] = plotyy(x1,y1,x2,y2,pltfcn); | |
194 hl = [H1 H2]; | |
195 % Set grid | |
196 grid(ha(1), 'on'); | |
197 grid(ha(2), 'on'); | |
198 | |
199 % Line color | |
200 set(H1, 'Color', colL); | |
201 set(H2, 'Color', colR); | |
202 % Line style | |
203 set(H1, 'LineStyle', styleL); | |
204 set(H2, 'LineStyle', styleR); | |
205 % Axis color | |
206 set(ha(1), 'XColor', 'k', 'YColor', colL); | |
207 set(ha(2), 'XColor', 'k', 'YColor', colR); | |
208 % Axis scales | |
209 set(ha(1), 'YScale', yscaleL); | |
210 set(ha(1), 'XScale', xscaleL); | |
211 set(ha(2), 'YScale', yscaleR); | |
212 set(ha(2), 'XScale', xscaleR); | |
213 | |
214 % Set y label 1 | |
215 ylabel(ha(2), [fixlabel(utils.plottools.label(a2.name)) ... | |
216 ' ' ... | |
217 fixlabel(char(a1.data.yunits)) ... | |
218 ]); | |
219 % Set y label 2 | |
220 ylabel(ha(1), [fixlabel(utils.plottools.label(a1.name)) ... | |
221 ' ' ... | |
222 fixlabel(char(a2.data.yunits))... | |
223 ]); | |
224 % Set x label | |
225 xlabel(ha(1), [XLabelString ' ' char(a1.data.xunits)]); | |
226 | |
227 % Print title | |
228 title(titleString); | |
229 | |
230 end % End fs_plot | |
231 | |
232 | |
233 %-------------------------------------------------------------------------- | |
234 % Get Info Object | |
235 %-------------------------------------------------------------------------- | |
236 function ii = getInfo(varargin) | |
237 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
238 sets = {}; | |
239 pl = []; | |
240 elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1}) | |
241 sets{1} = varargin{1}; | |
242 pl = getDefaultPlist(sets{1}); | |
243 else | |
244 sets = {'Time-series Plot', 'Frequency-series Plot', 'Y Plot', 'X-Y Plot', '3D Plot'}; | |
245 % get plists | |
246 pl(size(sets)) = plist; | |
247 for k = 1:numel(sets) | |
248 pl(k) = getDefaultPlist(sets{k}); | |
249 end | |
250 end | |
251 % Build info object | |
252 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.output, '$Id: iplotyy.m,v 1.14 2011/04/08 08:56:15 hewitson Exp $', sets, pl); | |
253 ii.setModifier(false); | |
254 ii.setArgsmin(2); | |
255 ii.setOutmin(0); | |
256 end | |
257 | |
258 %-------------------------------------------------------------------------- | |
259 % Get Default Plist | |
260 %-------------------------------------------------------------------------- | |
261 function plout = getDefaultPlist(set) | |
262 persistent pl; | |
263 persistent lastset; | |
264 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set) | |
265 pl = buildplist(set); | |
266 lastset = set; | |
267 end | |
268 plout = pl; | |
269 end | |
270 | |
271 function out = buildplist(varargin) | |
272 | |
273 set = ''; | |
274 if nargin == 1 | |
275 set = varargin{1}; | |
276 end | |
277 | |
278 % Get the LTPDA color set for lines | |
279 colors = getappdata(0,'ltpda_default_plot_colors'); | |
280 | |
281 out = plist(... | |
282 'LeftColor', colors{1}, ... | |
283 'RightColor', colors{2}, ... | |
284 'LeftLineStyle', '-', ... | |
285 'RightLineStyle', '-'); | |
286 | |
287 switch lower(set) | |
288 case 'frequency-series plot' | |
289 out.append(... | |
290 'LeftYScale', 'log', ... | |
291 'RightYScale', 'log', ... | |
292 'LeftXScale', 'log', ... | |
293 'RightXScale', 'log'); | |
294 case 'time-series plot' | |
295 out.append(... | |
296 'LeftYScale', 'lin', ... | |
297 'RightYScale', 'lin', ... | |
298 'LeftXScale', 'lin', ... | |
299 'RightXScale', 'lin'); | |
300 case 'x-y plot' | |
301 out.append(... | |
302 'LeftYScale', 'lin', ... | |
303 'RightYScale', 'lin', ... | |
304 'LeftXScale', 'lin', ... | |
305 'RightXScale', 'lin'); | |
306 case '3d plot' | |
307 case 'y plot' | |
308 otherwise | |
309 error('### Unknown set [%s]', set); | |
310 end | |
311 end | |
312 | |
313 | |
314 % Perform some substitutions on the labels | |
315 function ss = fixlabel(ss) | |
316 | |
317 wasCell = true; | |
318 if ~iscell(ss) | |
319 ss = {ss}; | |
320 wasCell = false; | |
321 end | |
322 | |
323 for kk=1:numel(ss) | |
324 s = ss{kk}; | |
325 | |
326 % Replace all ^(...) with ^{...} | |
327 j = 1; | |
328 while j<numel(s) | |
329 if strcmp(s(j:j+1), '^(') | |
330 % find next ) | |
331 for k=1:numel(s)-j+1 | |
332 if s(j+k) == ')' | |
333 s(j+1) = '{'; | |
334 s(j+k) = '}'; | |
335 break; | |
336 end | |
337 end | |
338 end | |
339 j = j + 1; | |
340 end | |
341 % Replace all .^ with ^ | |
342 s = strrep(s, '.^', '^'); | |
343 | |
344 % reduce size | |
345 if length(s) > 25 | |
346 addStr = '...'; | |
347 else | |
348 addStr = ''; | |
349 end | |
350 ssize = min(25, length(s)); | |
351 s = [s(1:ssize) addStr]; | |
352 | |
353 ss(kk) = {s}; | |
354 end | |
355 | |
356 | |
357 if ~wasCell | |
358 ss = ss{1}; | |
359 end | |
360 | |
361 end |