IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
draw_loadings_pl.m
Go to the documentation of this file.
1 %>@ingroup graphicsapi
2 %> @file
3 %> @brief Draws loadings curves with many options
4 %
5 %> @param x [nf] x-axis values.
6 %> @param L [nf][number_of_loadings] loadings matrix.
7 %> @param x_hint =[]. [nf] x-axis values. If not passed or empty, uses @a x if @a hint is passed.
8 %> @param hint [nf] "hint" curve that helps the reading of the loadings. If not passed or empty, no hint curve is drawn.
9 %> @param legends =[] One legend per loadings curve. If not passed, no legend is drawn.
10 %> @param flag_abs =0 Whether to take the absolute value of the loadings matrix.
11 %> @param peakd =[] Peak Detector object.
12 %> @param flag_trace_minalt =0 Whether to draw the threshold line. Only works if @a threshold is passed.
13 %> @param flag_draw_peaks =0 Whether to mark the detected peaks in the figure.
14 %> @param flag_print_peaks =0 Whether to print detected peaks on the command line window.
15 %> @param flag_histogram =0 Whether to plot line or histogram.
16 %> @param flag_envelope =0 If true, will detect all peaks, do spline interpolation and plot this instead
17 %> @param flag_bmtable =0 Alternative view. If true, a completely different thing will be done: a @ref bmtable will be created. Note that the peakdetector must be provided
18 %> @param colorindexes =[] If passed, will use indexes to find colors and markers. Otherwise, will assume [1, 2, 3, ...]
19 function draw_loadings_pl(x, L, x_hint, hint, legends, flag_abs, peakd, colorindexes)
20 % global SCALE;
21 if ~exist('x_hint', 'var') || isempty(x_hint)
22  x_hint = x;
23 end;
24 if ~exist('hint', 'var') || isempty(hint)
25  hint = [];
26 end;
27 if ~exist('legends', 'var')
28  legends = [];
29 end;
30 if ~exist('peakd', 'var')
31  peakd = [];
32 end;
33 if ~exist('flag_abs', 'var') || isempty(flag_abs)
34  flag_abs = 0;
35 end;
36 
37 nl = size(L, 2);
38 
39 if ~exist('colorindexes', 'var') || isempty(colorindexes)
40  colorindexes = 1:nl;
41 end;
42 
43 
44 if flag_abs
45  L = abs(L);
46 end;
47 
48 
49 % colors and markers
50 arts = cell(1, nl);
51 for i = 1:nl
52  a = bmart();
53  a.color = find_color(colorindexes(i));
54  a.marker = find_marker(colorindexes(i));
55  a.markerscale = 1;
56  arts{i} = a;
57 end;
58 
59 % hint
60 dshint = [];
61 if ~isempty(hint)
62  dshint = irdata();
63  dshint.X = hint(:)';
64  dshint.fea_x = x_hint;
65  dshint = dshint.assert_fix();
66 end;
67 
68 % Legends
69 bl = fcon_linear_fixed();
70 bl.L = L;
71 bl.L_fea_x = x;
72 if ~isempty(legends)
73  bl.L_fea_names = legends;
74  bl.title = '';
75 end;
76 
77 % Legends for the figure. bmtable will use dataset title as legend
78 %
79 % dss will be passed to bmtable as datasets. The only property that bmtable accesses is .title anyway.
80 for i = 1:nl
81  if isempty(legends)
82  dss(i).title = sprintf('Curve %s', i);
83  else
84  dss(i).title = legends{i};
85  end;
86 end;
87 
88 bm = bmtable();
89 bm.blocks = {bl};
90 bm.flag_train = 0;
91 bm.peakdetectors = {peakd};
92 bm.datasets = dss;
93 
94 bm.arts = arts;
95 bm.units = {bmunit_au};
96 bm.data_hint = dshint;
97 
98 
99 for i = nl:-1:1
100  bm.grid{i, 1} = setbatch(struct(), {'i_block', 1, 'i_dataset', i, 'i_peakdetector', 1, 'i_art', i, 'i_unit', 1, 'params', {'idx_fea', i}});
101 end;
102 bm.rowname_type = 'dataset';
103 
104 bm.draw_pl();
105 legend off;
function find_marker(in i)
function find_color(in i)
Dataset class.
Definition: irdata.m:30
Peak Detector.
Definition: peakdetector.m:6
Art stuff for BioMarker Tables.
Definition: bmart.m:5
function setbatch(in o, in params)
Unit - Arbitrary.
Definition: bmunit_au.m:5
Loadings vector specified directly.
Analysis Session (AS) base class.
Definition: as.m:6
BioMarker Table.
Definition: bmtable.m:22
function draw_loadings_pl(in x, in L, in x_hint, in hint, in legends, in flag_abs, in peakd, in colorindexes)