comparison m-toolbox/test/new_plot/miplot.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 function varargout = miplot(varargin)
2 % MIPLOT provides an intelligent plotting tool for LTPDA.
3 %
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 %
6 % DESCRIPTION: MIPLOT provides an intelligent plotting tool for LTPDA.
7 %
8 % CALL: h = plot (a,pl)
9 %
10 % INPUTS: pl - a parameter list
11 % a - input analysis object
12 %
13 % OUTPUTS: h - handles to plot objects
14 %
15 % Plot parameters:
16 %
17 % 'type' - one of the data class types
18 % 'tsdata' [default], 'fsdata', 'cdata', 'xydata', 'xyzdata'.
19 %
20 % 'Arrangement' - select the plot layout:
21 % 'single' - plots all AOs on individual figures
22 % 'stacked' - plots all AOs on the same axes [default]
23 % 'subplots' - plots all AOs on subplots
24 %
25 % Line parameters:
26 %
27 % The following properties take cell array values. If the length of
28 % the cell array is shorter than the number of lines to plot, the
29 % remaining lines will be plotted with the default options.
30 %
31 % 'Colors' - a cell array of color definitions which will be
32 % looped over for each line.
33 %
34 % 'LineStyles' - a cell array of line styles.
35 %
36 % 'Legends' - specify a cell array of strings to be used for
37 % the plot legends. If a cell contains an empty
38 % string, the default legend string is built.
39 % If a single string 'off' is given instead of a
40 % cell array, then the legends are all switched
41 % off.
42 %
43 % 'XLabels' - Specify the labels to be used on the x-axis. The
44 % units are added from the data object 'xunits'
45 % property.
46 %
47 % 'YLabels' - Specify the labels to be used on the y-axis. The
48 % units are added from the data object 'yunits'
49 % property. If the object contains complex data,
50 % you should specify two y-labels for that object.
51 %
52 % 'XScales' - Specify the scales to be used on the x-axes.
53 %
54 % 'YScales' - Specify the scales to the used on the y-axes. If
55 % an object contains complex data, you should
56 % specify two y-labels for that object.
57 %
58 % 'LineWidths' - an array of line widths. If the length of the
59 % array is shorter than the number of lines to
60 % plot, the remaining lines will be plotted with
61 % the default line width.
62 %
63 %
64 %
65 %
66 %
67 % VERSION: $Id: miplot.m,v 1.3 2008/02/07 19:51:53 hewitson Exp $
68 %
69 % The following call returns a parameter list object that contains the
70 % default parameter values:
71 %
72 % >> pl = miplot(ao, 'Params')
73 %
74 % HISTORY: 22-12-07 M Hewitson
75 % Creation
76 %
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %
82 % TODO:
83 % 1) Add XRange, YRange, ZRange
84 % 2) Add/test math functions to all plots
85 %
86 %
87
88 %% Check if this is a call for parameters
89
90 VERSION = '$Id: miplot.m,v 1.3 2008/02/07 19:51:53 hewitson Exp $';
91 bs = [];
92
93 if nargin == 2
94 if isa(varargin{1}, 'ao') && ischar(varargin{2})
95 in = char(varargin{2});
96 if strcmp(in, 'Params')
97 varargout{1} = getDefaultPL();
98 return
99 elseif strcmp(in, 'Version')
100 varargout{1} = VERSION;
101 return
102 end
103 end
104 end
105
106 %% Collect input ao's, plist's and ao variable names
107 in_names = {};
108 for ii = 1:nargin
109 in_names{end+1} = inputname(ii);
110 end
111
112 [as, upl, invars] = collect_inputs(varargin, in_names);
113
114 %% Go through AOs and collect them into similar types
115
116 tsAOs = [];
117 fsAOs = [];
118 xyAOs = [];
119 xyzAOs = [];
120 cAOs = [];
121
122 for j=1:numel(as)
123 switch class(as(j).data)
124 case 'tsdata'
125 tsAOs = [tsAOs as(j)];
126 case 'fsdata'
127 fsAOs = [fsAOs as(j)];
128 case 'xydata'
129 xyAOs = [xyAOs as(j)];
130 case 'xyzdata'
131 xyzAOs = [xyzAOs as(j)];
132 case 'cdata'
133 cAOs = [cAOs as(j)];
134 otherwise
135 warning('!!! Unknown data type %s', class(as(j).data));
136 end
137 end
138
139 %% Now plot all the objects on separate figures
140
141 %----------- TSDATA
142
143 % get default plist
144 dpl = getDefaultPlist('tsdata');
145 % combine the plists
146 pl = combine(upl, dpl);
147 % Call x-y plot
148 [hfig, hax, hli] = xy_plot(tsAOs, pl);
149
150 %----------- XYDATA
151
152 % get default plist
153 dpl = getDefaultPlist('xydata');
154 % combine the plists
155 pl = combine(upl, dpl);
156 % Call x-y plot
157 [hfig, hax, hli] = xy_plot(xyAOs, pl);
158
159 %----------- XYZDATA
160
161 % get default plist
162 dpl = getDefaultPlist('xyzdata');
163 % combine the plists
164 pl = combine(upl, dpl);
165 % Call x-y-z plot
166 [hfig, hax, hli] = xyz_plot(xyzAOs, pl);
167
168 %----------- CDATA
169
170 % get default plist
171 dpl = getDefaultPlist('cdata');
172 % combine the plists
173 pl = combine(upl, dpl);
174 % Call x-y plot
175 [hfig, hax, hli] = y_plot(cAOs, pl);
176
177 %----------- FSDATA
178
179 % get default plist
180 dpl = getDefaultPlist('fsdata');
181 % combine the plists
182 pl = combine(upl, dpl);
183 % Call fsdata plot
184 [hfig, hax, hli] = fs_plot(fsAOs, pl);
185
186
187 %--------------------------------------------------------------------------
188 % Plot fsdata objects
189 %
190 function varargout = fs_plot(varargin)
191
192 aos = varargin{1};
193 pl = varargin{2};
194
195 % Extract parameters
196 arrangement = find(pl, 'Arrangement');
197 colors = find(pl, 'Colors');
198 linestyles = find(pl, 'LineStyles');
199 linewidths = find(pl, 'LineWidths');
200 legends = find(pl, 'Legends');
201 ylabels = find(pl, 'YLabels');
202 xlabels = find(pl, 'XLabels');
203 yscales = find(pl, 'YScales');
204 xscales = find(pl, 'XScales');
205 yranges = find(pl, 'YRanges');
206 xranges = find(pl, 'XRanges');
207 xmaths = find(pl, 'XMaths');
208 ymaths = find(pl, 'YMaths');
209 complexPlotType = find(pl, 'complexPlotType');
210
211 % check whether we want legends or not
212 if iscell(legends)
213 legendsOn = 1;
214 else
215 if strcmpi(legends, 'off')
216 legendsOn = 0;
217 else
218 legendsOn = 1;
219 legends = [];
220 end
221 end
222
223 if ~iscell(linestyles), linestyles = {linestyles}; end
224 if ~iscell(legends), legends = {legends}; end
225 if ~iscell(ylabels), ylabels = {ylabels}; end
226 if ~iscell(xlabels), xlabels = {xlabels}; end
227 if ~iscell(xmaths), xmaths = {xmaths}; end
228 if ~iscell(ymaths), ymaths = {ymaths}; end
229 if ~iscell(xscales), xscales = {xscales}; end
230 if ~iscell(yscales), yscales = {yscales}; end
231 if ~iscell(xranges), xranges = {xranges}; end
232 if ~iscell(yranges), yranges = {yranges}; end
233
234
235 % collect figure handles
236 tsfig = [];
237 tsax = [];
238 tsli = [];
239
240 % Legend holder
241 legendStr = [];
242
243 if ~isempty(aos)
244
245 % Now loop over AOs
246 Na = length(aos);
247
248 % - first to check if any are complex
249 haveComplex = 0;
250 for j=1:Na
251 a = aos(j);
252 y = a.data.y;
253 ymath = '';
254 if j<=length(ymaths)
255 if ~isempty(ymaths{j})
256 eval(sprintf('y = %s;', ymaths{j}));
257 ymath = ymaths{j};
258 end
259 end
260 xmath = '';
261 if j<=length(xmaths)
262 if ~isempty(xmaths{j})
263 eval(sprintf('x = %s;', xmaths{j}));
264 xmath = xmaths{j};
265 end
266 end
267 if ~isreal(y)
268 haveComplex = 1;
269 end
270 end
271
272 % Loop over the AOs now
273 for j=1:Na
274
275 % set real and imag subplot handles to empty
276 tsax_r = [];
277 tsax_i = [];
278
279 % Get this AO
280 a = aos(j);
281
282 %------- Apply math functions
283 x = a.data.x;
284 y = a.data.y;
285
286 ymath = '';
287 if j<=length(ymaths)
288 if ~isempty(ymaths{j})
289 eval(sprintf('y = %s;', ymaths{j}));
290 ymath = ymaths{j};
291 end
292 end
293 xmath = '';
294 if j<=length(xmaths)
295 if ~isempty(xmaths{j})
296 eval(sprintf('x = %s;', xmaths{j}));
297 xmath = xmaths{j};
298 end
299 end
300
301 % what figures do we need?
302 switch arrangement
303 case 'single'
304
305 tsfig = [tsfig figure];
306 col = colors{1};
307 % check if this data set is real or complex
308 if ~isreal(y)
309 % complex means we use two subplots
310 tsax_r = subplot(2,1,1);
311 tsax_i = subplot(2,1,2);
312 tsax = [tsax tsax_r tsax_i];
313 else
314 % real means we use a single subplot
315 tsax_r = subplot(1, 1, 1);
316 tsax = [tsax tsax_r];
317 end
318
319 case 'stacked'
320
321 if j==1, tsfig = figure; end
322 % if at least one of the input fsdata AOs is complex, we need to
323 % allow for subplots
324 if haveComplex
325 tsax_r = subplot(2,1,1);
326 tsax_i = subplot(2,1,2);
327 tsax = [tsax_r tsax_i];
328 else
329 tsax_r = subplot(1, 1, 1);
330 tsax = tsax_r;
331 end
332 col = colors{mod(j-1,length(colors))+1};
333 hold(tsax_r, 'on');
334 if ishandle(tsax_i)
335 hold(tsax_i, 'on');
336 end
337 case 'subplots'
338
339 if j == 1, tsfig = figure; end
340 c = 1+(j-1)*2;
341 sx = Na;
342 sy = 2;
343 % Now we have one or two subplots per input object.
344 if ~isreal(y)
345 tsax_r = subplot(sx, sy,c);
346 tsax_i = subplot(sx, sy,c+1);
347 tsax = [tsax tsax_r tsax_i];
348 else
349 tsax_r = subplot(sx, sy, c:c+1);
350 tsax = [tsax tsax_r];
351 end
352 col = colors{1};
353
354 otherwise
355 error('### Unknown plot arrangement');
356 end
357
358 %------- Plot the data
359
360 % plot real or complex data and setup default values for scale and
361 % labels as we go.
362 if isreal(y)
363 tsli = [tsli plot(tsax_r, x, y)];
364 ylabelr = 'amplitude';
365 ylabeli = 'imag';
366 yscaleR = 'log';
367 yscaleI = 'lin';
368 xscaleR = 'log';
369 xscaleI = 'lin';
370 else
371 switch complexPlotType
372 case 'realimag'
373 tsli = [tsli plot(tsax_r, x, real(y))];
374 tsli = [tsli plot(tsax_i, x, imag(y))];
375 ylabelr = 'real';
376 ylabeli = 'imag';
377 yscaleR = 'lin';
378 yscaleI = 'lin';
379 xscaleR = 'lin';
380 xscaleI = 'lin';
381 case 'absdeg'
382 tsli = [tsli plot(tsax_r, x, abs(y))];
383 tsli = [tsli plot(tsax_i, x, phase(y))];
384 ylabelr = 'amplitude';
385 ylabeli = 'Phase [deg]';
386 yscaleR = 'log';
387 yscaleI = 'lin';
388 xscaleR = 'log';
389 xscaleI = 'log';
390 case 'absrad'
391 tsli = [tsli plot(tsax_r, x, abs(y))];
392 tsli = [tsli plot(tsax_i, x, angle(y))];
393 ylabelr = 'amplitude';
394 ylabeli = 'phase [rad]';
395 yscaleR = 'log';
396 yscaleI = 'lin';
397 xscaleR = 'log';
398 xscaleI = 'log';
399 otherwise
400 error('### Unknown plot type for complex data');
401 end
402 end
403
404 %------- Axis properties
405
406 % Set ylabel
407 c = 1+(j-1)*2;
408 if c<=length(ylabels)
409 if ~isempty(ylabels{c})
410 ylstrR = ylabels{c};
411 else
412 ylstrR = ylabelr;
413 end
414 else
415 ylstrR = ylabelr;
416 end
417 if c<length(ylabels)
418 if ~isempty(ylabels{c+1})
419 ylstrI = ylabels{c+1};
420 else
421 ylstrI = ylabeli;
422 end
423 else
424 ylstrI = ylabeli;
425 end
426 if ~isempty(ymath)
427 ymath = strrep(ymath, 'y', sprintf('%s', a.data.yunits));
428 ylstrR = [ylstrR ' [' ymath ']' ];
429 else
430 ylstrR = [ylstrR ' [' a.data.yunits ']' ];
431 end
432 ylabel(tsax_r, ylstrR);
433 if ishandle(tsax_i)
434 ylabel(tsax_i, ylstrI);
435 end
436
437 % Set xlabel
438 if j<=length(xlabels) && ~isempty(xlabels{j})
439 xlstr = xlabels{j};
440 else
441 xlstr = find(pl, 'XLabel');
442 end
443 if ~isempty(xmath)
444 xmath = strrep(xmath, 'x', sprintf('%s', a.data.xunits));
445 xlstr = [xlstr ' [' xmath ']' ];
446 else
447 xlstr = [xlstr ' [' a.data.xunits ']' ];
448 end
449 xlabel(tsax_r, xlstr);
450 if ishandle(tsax_i)
451 xlabel(tsax_i, xlstr);
452 end
453
454 % Set grid on or off
455 grid(tsax_r, 'on');
456 if ishandle(tsax_i)
457 grid(tsax_i, 'on');
458 end
459
460 % Set Y scale
461 c = 1+(j-1)*2;
462 if c<=length(yscales)
463 if ~isempty(yscales{c})
464 yscaleR = yscales{c};
465 end
466 end
467 if c<length(yscales)
468 if ~isempty(yscales{c+1})
469 yscaleI = yscales{c+1};
470 end
471 end
472 set(tsax_r, 'YScale', yscaleR);
473 if ishandle(tsax_i)
474 set(tsax_i, 'YScale', yscaleI);
475 end
476
477 % Set X scale
478 c = 1+(j-1)*2;
479 if c<=length(xscales)
480 if ~isempty(xscales{c})
481 xscaleR = xscales{c};
482 end
483 end
484 if c<length(xscales)
485 if ~isempty(xscales{c+1})
486 xscaleI = xscales{c+1};
487 end
488 end
489 set(tsax_r, 'XScale', xscaleR);
490 if ishandle(tsax_i)
491 set(tsax_i, 'XScale', xscaleI);
492 end
493
494 % Set Y range
495 c = 1+(j-1)*2;
496 if c<=length(yranges)
497 if ~isempty(yranges{c})
498 set(tsax_r, 'YLim', yranges{c});
499 end
500 end
501 if c<length(yranges)
502 if ~isempty(yranges{c+1})
503 if ishandle(tsax_i)
504 set(tsax_i, 'YLim', yranges{c+1});
505 end
506 end
507 end
508
509 % Set X range
510 c = 1+(j-1)*2;
511 if c<=length(xranges)
512 if ~isempty(xranges{c})
513 set(tsax_r, 'XLim', xranges{c});
514 end
515 end
516 if c<length(xranges)
517 if ~isempty(xranges{c+1})
518 if ishandle(tsax_i)
519 set(tsax_i, 'XLim', xranges{c+1});
520 end
521 end
522 end
523
524 %------- line properties
525
526 % Set line color
527 if isreal(y)
528 set(tsli(end), 'Color', col);
529 else
530 set(tsli(end-1), 'Color', col);
531 set(tsli(end), 'Color', col);
532 end
533
534 % Set line style
535 if j<=length(linestyles) && ~isempty(linestyles{j})
536 if isreal(y)
537 set(tsli(end), 'LineStyle', linestyles{j});
538 else
539 set(tsli(end-1), 'LineStyle', linestyles{j});
540 set(tsli(end), 'LineStyle', linestyles{j});
541 end
542 end
543
544 % Set line widths
545 if j<=length(linewidths) && ~isempty(linewidths(j))
546 if isreal(y)
547 set(tsli(end), 'LineWidth', linewidths(j));
548 else
549 set(tsli(end-1), 'LineWidth', linewidths(j));
550 set(tsli(end), 'LineWidth', linewidths(j));
551 end
552 end
553
554 % Set legend string
555 lstr = '';
556 if legendsOn
557 if j<=length(legends) && ~isempty(legends{j})
558 lstr = legends{j};
559 else
560 lstr = ltpda_label(a.name);
561 end
562 end
563 legendStr = [legendStr cellstr(lstr)];
564
565 % Set the legend now if we can
566 if legendsOn
567 if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
568 legend(tsax_r, legendStr{end});
569 end
570 end
571
572 end % End loop over AOs
573
574 % Process legends for stacked plots
575 if legendsOn
576 if strcmp(arrangement, 'stacked')
577 h = legend(tsax_r, legendStr);
578 set(h, 'FontSize', 10)
579 end
580 end
581
582 end
583
584 % Set outputs
585 if nargout > 0
586 varargout{1} = tsfig;
587 end
588 if nargout > 1
589 varargout{2} = tsax;
590 end
591 if nargout == 3
592 varargout{3} = tsli;
593 end
594 if nargout > 3
595 error('### Too many output arguments');
596 end
597
598 %--------------------------------------------------------------------------
599 % Plot tsdata and xydata objects
600 %
601 function varargout = xy_plot(varargin)
602
603 aos = varargin{1};
604 pl = varargin{2};
605
606 % Extract parameters
607 arrangement = find(pl, 'Arrangement');
608 colors = find(pl, 'Colors');
609 linestyles = find(pl, 'LineStyles');
610 linewidths = find(pl, 'LineWidths');
611 legends = find(pl, 'Legends');
612 ylabels = find(pl, 'YLabels');
613 xlabels = find(pl, 'XLabels');
614 xmaths = find(pl, 'XMaths');
615 ymaths = find(pl, 'YMaths');
616
617 % check whether we want legends or not
618 if iscell(legends)
619 legendsOn = 1;
620 else
621 if strcmpi(legends, 'off')
622 legendsOn = 0;
623 else
624 legendsOn = 1;
625 legends = [];
626 end
627 end
628
629 if ~iscell(linestyles), linestyles = {linestyles}; end
630 if ~iscell(legends), legends = {legends}; end
631 if ~iscell(ylabels), ylabels = {ylabels}; end
632 if ~iscell(xlabels), xlabels = {xlabels}; end
633 if ~iscell(xmaths), xmaths = {xmaths}; end
634 if ~iscell(ymaths), ymaths = {ymaths}; end
635
636
637 % collect figure handles
638 tsfig = [];
639 tsax = [];
640 tsli = [];
641
642 % Legend holder
643 legendStr = [];
644
645 if ~isempty(aos)
646
647 % Now loop over AOs
648 Na = length(aos);
649 for j=1:Na
650
651 % Get this AO
652 a = aos(j);
653
654 % what figures do we need?
655 switch arrangement
656 case 'single'
657
658 tsfig = [tsfig figure];
659 tsax = subplot(1,1,1);
660 col = colors{1};
661
662 case 'stacked'
663
664 if j==1, tsfig = figure; end
665 tsax = subplot(1,1,1);
666 col = colors{mod(j-1,length(colors))+1};
667 hold on;
668
669 case 'subplots'
670
671 if j == 1, tsfig = figure; end
672 tsax = [tsax subplot(Na, 1, j)];
673 col = colors{1};
674
675 otherwise
676 error('### Unknown plot arrangement');
677 end
678
679 %------- Apply math functions
680 x = a.data.x;
681 y = a.data.y;
682
683 ymath = '';
684 if j<=length(ymaths)
685 if ~isempty(ymaths{j})
686 eval(sprintf('y = %s;', ymaths{j}));
687 ymath = ymaths{j};
688 end
689 end
690 xmath = '';
691 if j<=length(xmaths)
692 if ~isempty(xmaths{j})
693 eval(sprintf('x = %s;', xmaths{j}));
694 xmath = xmaths{j};
695 end
696 end
697
698 %------- Plot the data
699
700 tsli = [tsli plot(tsax(end), x, y)];
701
702 %------- Axis properties
703
704 % Set ylabel
705 if j<=length(ylabels) && ~isempty(ylabels{j})
706 ylstr = ylabels{j};
707 else
708 ylstr = find(pl, 'YLabel');
709 end
710 if ~isempty(ymath)
711 ymath = strrep(ymath, 'y', sprintf('%s', a.data.yunits));
712 ylstr = [ylstr ' [' ymath ']' ];
713 else
714 ylstr = [ylstr ' [' a.data.yunits ']' ];
715 end
716 ylabel(ylstr);
717
718 % Set xlabel
719 if j<=length(xlabels) && ~isempty(xlabels{j})
720 xlstr = xlabels{j};
721 else
722 xlstr = find(pl, 'XLabel');
723 end
724 if ~isempty(xmath)
725 xmath = strrep(xmath, 'x', sprintf('%s', a.data.xunits));
726 xlstr = [xlstr ' [' xmath ']' ];
727 else
728 xlstr = [xlstr ' [' a.data.xunits ']' ];
729 end
730 xlabel(xlstr);
731
732
733 % Set grid on or off
734 grid(tsax(end), 'on');
735
736 %------- line properties
737
738 % Set line color
739 set(tsli(end), 'Color', col);
740
741 % Set line style
742 if j<=length(linestyles) && ~isempty(linestyles{j})
743 set(tsli(end), 'LineStyle', linestyles{j});
744 end
745
746 % Set line widths
747 if j<=length(linewidths) && ~isempty(linewidths(j))
748 set(tsli(end), 'LineWidth', linewidths(j));
749 end
750
751 % Set legend string
752 lstr = '';
753 if legendsOn
754 if j<=length(legends) && ~isempty(legends{j})
755 lstr = legends{j};
756 else
757 lstr = ltpda_label(a.name);
758 end
759 end
760 legendStr = [legendStr cellstr(lstr)];
761
762 % Set the legend now if we can
763 if legendsOn
764 if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
765 legend(legendStr{end});
766 end
767 end
768 end
769
770 % Process legends for stacked plots
771 if legendsOn
772 if strcmp(arrangement, 'stacked')
773 h = legend(legendStr);
774 set(h, 'FontSize', 10)
775 end
776 end
777
778 end
779
780 % Set outputs
781 if nargout > 0
782 varargout{1} = tsfig;
783 end
784 if nargout > 1
785 varargout{2} = tsax;
786 end
787 if nargout == 3
788 varargout{3} = tsli;
789 end
790 if nargout > 3
791 error('### Too many output arguments');
792 end
793
794
795 %--------------------------------------------------------------------------
796 % Plot cdata objects
797 %
798 function varargout = y_plot(varargin)
799
800 aos = varargin{1};
801 pl = varargin{2};
802
803 % Extract parameters
804 arrangement = find(pl, 'Arrangement');
805 colors = find(pl, 'Colors');
806 linestyles = find(pl, 'LineStyles');
807 linewidths = find(pl, 'LineWidths');
808 legends = find(pl, 'Legends');
809 ylabels = find(pl, 'YLabels');
810 xlabels = find(pl, 'XLabels');
811 xmaths = find(pl, 'XMaths');
812 ymaths = find(pl, 'YMaths');
813
814 % check whether we want legends or not
815 if iscell(legends)
816 legendsOn = 1;
817 else
818 if strcmp(legends, 'off')
819 legendsOn = 0;
820 else
821 legendsOn = 1;
822 legends = [];
823 end
824 end
825
826 if ~iscell(linestyles), linestyles = {linestyles}; end
827 if ~iscell(legends), legends = {legends}; end
828 if ~iscell(ylabels), ylabels = {ylabels}; end
829 if ~iscell(xlabels), xlabels = {xlabels}; end
830 if ~iscell(xmaths), xmaths = {xmaths}; end
831 if ~iscell(ymaths), ymaths = {ymaths}; end
832
833 % collect figure handles
834 tsfig = [];
835 tsax = [];
836 tsli = [];
837
838 % Legend holder
839 legendStr = [];
840
841 if ~isempty(aos)
842
843 % Now loop over AOs
844 Na = length(aos);
845 for j=1:Na
846
847 % Get this AO
848 a = aos(j);
849
850 % what figures do we need?
851 switch arrangement
852 case 'single'
853
854 tsfig = [tsfig figure];
855 tsax = subplot(1,1,1);
856 col = colors{1};
857
858 case 'stacked'
859
860 if j==1, tsfig = figure; end
861 tsax = subplot(1,1,1);
862 col = colors{mod(j-1,length(colors))+1};
863 hold on;
864
865 case 'subplots'
866
867 if j == 1, tsfig = figure; end
868 tsax = [tsax subplot(Na, 1, j)];
869 col = colors{1};
870
871 otherwise
872 error('### Unknown plot arrangement');
873 end
874
875 %------- Apply math functions
876 x = 1:length(a.data.y);
877 y = a.data.y;
878
879 ymath = '';
880 if j<=length(ymaths)
881 if ~isempty(ymaths{j})
882 eval(sprintf('y = %s;', ymaths{j}));
883 ymath = ymaths{j};
884 end
885 end
886 xmath = '';
887 if j<=length(xmaths)
888 if ~isempty(xmaths{j})
889 eval(sprintf('x = %s;', xmaths{j}));
890 xmath = xmaths{j};
891 end
892 end
893
894 %------- Plot the data
895
896 idcs = plot(tsax(end), x, y);
897 tsli = [tsli idcs(1:end).'];
898
899 %------- Axis properties
900
901 % Set ylabel
902 if j<=length(ylabels) && ~isempty(ylabels{j})
903 ylstr = ylabels{j};
904 else
905 ylstr = find(pl, 'YLabel');
906 end
907 if ~isempty(ymath)
908 ymath = strrep(ymath, 'y', sprintf('%s', a.data.yunits));
909 ylstr = [ylstr ' [' ymath ']' ];
910 else
911 ylstr = [ylstr ' [' a.data.yunits ']' ];
912 end
913 ylabel(ylstr);
914
915 % Set xlabel
916 if j<=length(xlabels) && ~isempty(xlabels{j})
917 xlstr = xlabels{j};
918 else
919 xlstr = find(pl, 'XLabel');
920 end
921 if ~isempty(xmath)
922 xmath = strrep(xmath, 'x', sprintf('%s', a.data.xunits));
923 xlstr = [xlstr ' [' xmath ']' ];
924 else
925 xlstr = [xlstr ' [' a.data.xunits ']' ];
926 end
927 xlabel(xlstr);
928
929
930 % Set grid on or off
931 grid(tsax(end), 'on');
932
933 %------- line properties
934
935 % Set line color
936 set(tsli(end), 'Color', col);
937
938 % Set line style
939 if j<=length(linestyles) && ~isempty(linestyles{j})
940 set(tsli(end), 'LineStyle', linestyles{j});
941 end
942
943 % Set line widths
944 if j<=length(linewidths)
945 set(tsli(end), 'LineWidth', linewidths(j));
946 end
947
948 % Set legend string
949 if legendsOn
950 if j<=length(legends) && ~isempty(legends{j})
951 legendStr = [legendStr legends(j)];
952 else
953 lstr = ltpda_label(a.name);
954 legendStr = [legendStr cellstr(lstr)];
955 end
956 end
957
958 % Set the legend now if we can
959 if legendsOn
960 if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
961 legend(legendStr{end});
962 end
963 end
964 end
965
966 % Process legends for stacked plots
967 if legendsOn
968 if strcmp(arrangement, 'stacked')
969 h = legend(legendStr);
970 set(h, 'FontSize', 10)
971 end
972 end
973
974 end
975
976 % Set outputs
977 if nargout > 0
978 varargout{1} = tsfig;
979 end
980 if nargout > 1
981 varargout{2} = tsax;
982 end
983 if nargout == 3
984 varargout{3} = tsli;
985 end
986 if nargout > 3
987 error('### Too many output arguments');
988 end
989
990 %--------------------------------------------------------------------------
991 % Plot xyzdata objects
992 %
993 function varargout = xyz_plot(varargin)
994
995 aos = varargin{1};
996 pl = varargin{2};
997
998 % Extract parameters
999 arrangement = find(pl, 'Arrangement');
1000 colors = find(pl, 'Colors');
1001 linestyles = find(pl, 'LineStyles');
1002 linewidths = find(pl, 'LineWidths');
1003 legends = find(pl, 'Legends');
1004 zlabels = find(pl, 'ZLabels');
1005 ylabels = find(pl, 'YLabels');
1006 xlabels = find(pl, 'XLabels');
1007 xmaths = find(pl, 'XMaths');
1008 ymaths = find(pl, 'YMaths');
1009 zmaths = find(pl, 'ZMaths');
1010
1011 % check whether we want legends or not
1012 if iscell(legends)
1013 legendsOn = 1;
1014 else
1015 if strcmp(legends, 'off')
1016 legendsOn = 0;
1017 else
1018 legendsOn = 1;
1019 legends = [];
1020 end
1021 end
1022
1023 % collect figure handles
1024 tsfig = [];
1025 tsax = [];
1026 tsli = [];
1027
1028 % Legend holder
1029 legendStr = [];
1030
1031 if ~isempty(aos)
1032
1033 % Now loop over AOs
1034 Na = length(aos);
1035 for j=1:Na
1036
1037 % Get this AO
1038 a = aos(j);
1039
1040 % what figures do we need?
1041 switch arrangement
1042 case 'single'
1043
1044 tsfig = [tsfig figure];
1045 tsax = subplot(1,1,1);
1046
1047 case 'subplots'
1048
1049 if j == 1, tsfig = figure; end
1050 tsax = [tsax subplot(Na, 1, j)];
1051
1052 otherwise
1053 error('### Unknown plot arrangement');
1054 end
1055
1056 %------- Apply math functions
1057 x = a.data.x;
1058 y = a.data.y;
1059 z = a.data.z;
1060
1061
1062 ymath = '';
1063 if j<=length(ymaths)
1064 if ~isempty(ymaths{j})
1065 eval(sprintf('y = %s;', ymaths{j}));
1066 ymath = ymaths{j};
1067 end
1068 end
1069 xmath = '';
1070 if j<=length(xmaths)
1071 if ~isempty(xmaths{j})
1072 eval(sprintf('x = %s;', xmaths{j}));
1073 xmath = xmaths{j};
1074 end
1075 end
1076 zmath = '';
1077 if j<=length(zmaths)
1078 if ~isempty(zmaths{j})
1079 eval(sprintf('z = %s;', zmaths{j}));
1080 zmath = zmaths{j};
1081 end
1082 end
1083
1084 %------- Plot the data
1085
1086 idcs = pcolor(x,y,z);
1087 tsli = [tsli idcs(1:end).'];
1088
1089 % plot properties
1090 set(idcs, 'EdgeColor', 'none');
1091
1092 %------- Axis properties
1093
1094 % Reverse y-direction for spectrograms
1095 set(tsax(end), 'YDir', 'reverse');
1096
1097 % Set ylabel
1098 if j<=length(ylabels) && ~isempty(ylabels{j})
1099 ylstr = ylabels{j};
1100 else
1101 ylstr = find(pl, 'YLabel');
1102 end
1103 if ~isempty(ymath)
1104 ymath = strrep(ymath, 'y', sprintf('%s', a.data.yunits));
1105 ylstr = [ylstr ' [' ymath ']' ];
1106 else
1107 ylstr = [ylstr ' [' a.data.yunits ']' ];
1108 end
1109 ylabel(ylstr);
1110
1111 % Set xlabel
1112 if j<=length(xlabels) && ~isempty(xlabels{j})
1113 xlstr = xlabels{j};
1114 else
1115 xlstr = find(pl, 'XLabel');
1116 end
1117 if ~isempty(xmath)
1118 xmath = strrep(xmath, 'x', sprintf('%s', a.data.xunits));
1119 xlstr = [xlstr ' [' xmath ']' ];
1120 else
1121 xlstr = [xlstr ' [' a.data.xunits ']' ];
1122 end
1123 xlabel(xlstr);
1124
1125 % Set grid on or off
1126 grid(tsax(end), 'on');
1127
1128 % Set title string
1129 if ~strcmpi(legends, 'off')
1130 if j<=length(legends) && ~isempty(legends{j})
1131 legendStr = [legendStr legends(j)];
1132 else
1133 lstr = ltpda_label(a.name);
1134 legendStr = [legendStr cellstr(lstr)];
1135 end
1136 end
1137
1138 % Set the legend now if we can
1139 tstr = legendStr{end};
1140 if legendsOn
1141 title(tstr);
1142 end
1143
1144 % Set colorbars
1145 hc = colorbar('peer', tsax(end));
1146 if j<=length(zlabels)
1147 if ~isempty(zlabels{j})
1148 zlstr = zlabels{j};
1149 end
1150 else
1151 zlstr = find(pl, 'Zlabel');
1152 end
1153 if ~isempty(zmath), zlstr = [zlstr sprintf('\n%s', zmath)]; end
1154 ylh = get(hc, 'YLabel');
1155 set(ylh, 'String', zlstr);
1156 set(ylh, 'Fontsize', get(tsax(end), 'Fontsize'))
1157 set(ylh, 'FontName', get(tsax(end), 'FontName'))
1158 set(ylh, 'FontAngle', get(tsax(end), 'FontAngle'))
1159 set(ylh, 'FontWeight', get(tsax(end), 'FontWeight'))
1160 end
1161 end
1162
1163 % Set outputs
1164 if nargout > 0
1165 varargout{1} = tsfig;
1166 end
1167 if nargout > 1
1168 varargout{2} = tsax;
1169 end
1170 if nargout == 3
1171 varargout{3} = tsli;
1172 end
1173 if nargout > 3
1174 error('### Too many output arguments');
1175 end
1176
1177
1178 %--------------------------------------------------------------------------
1179 % Default Parameter Lists
1180 %
1181 function out = getDefaultPlist(varargin)
1182
1183 % list of available parameter sets
1184 sets = {'tsdata', 'fsdata', 'cdata', 'xydata'};
1185
1186 % Get the LTPDA color set for lines
1187 colors = getappdata(0,'ltpda_default_plot_colors');
1188
1189 if nargin == 0
1190 out = sets;
1191 return
1192 end
1193
1194 set = varargin{1};
1195
1196 out = plist('Colors', colors, ...
1197 'Arrangement', 'stacked');
1198
1199 switch set
1200 case 'fsdata'
1201 out = append(out, 'type', 'fsdata', ...
1202 'complexPlotType', 'absdeg', ...
1203 'XLabel', 'Frequency');
1204 case 'tsdata'
1205 out = append(out, 'type', 'tsdata', ...
1206 'Xlabel', 'Time', ...
1207 'Ylabel', 'Amplitude');
1208 case 'xydata'
1209 out = append(out, 'type', 'xydata', ...
1210 'Xlabel', 'X-data', ...
1211 'Ylabel', 'Y-data', ...
1212 'YMaths', '', ...
1213 'XMaths', '');
1214 case 'xyzdata'
1215 out = plist('Colors', colors, 'Arrangement', 'single', ...
1216 'type', 'xydata', ...
1217 'Xlabel', 'Time', ...
1218 'Ylabel', 'Frequency',...
1219 'Zlabel', 'Amplitude', ...
1220 'YMaths', '', ...
1221 'ZMaths', '', ...
1222 'XMaths', '');
1223 case 'cdata'
1224 out = append(out, 'type', 'tsdata', ...
1225 'Xlabel', 'Index', ...
1226 'Ylabel', 'Value');
1227 otherwise
1228 out = plist();
1229 end
1230
1231