IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
draw_stacked.m
Go to the documentation of this file.
1 %>@ingroup graphicsapi
2 %> @file
3 %> @brief Draws stacked histograms
4 %>
5 %> Uses BAR(..., 'stacked') to do the job
6 %
7 %> @param x [nf] x-axis values.
8 %> @param histss [no_hists][nf] hits matrix
9 %> @param no_informative Number of histograms that are considered "informative"
10 %> @param colors See @ref colors2map.m
11 %> @param x_hint =[]. [nf] x-axis values. If not passed or empty, uses @a x if @a hint is passed.
12 %> @param hint [nf] "hint" curve that helps the reading of the loadings. If not passed or empty, no hint curve is drawn.
13 %> @param peakd =[] Peak Detector object.
14 %> @param flag_trace_minalt =~isempty(peakd) Whether to draw the threshold line. Only works if the peak detector is passed.
15 %> @param flag_draw_peaks =~isempty(peakd) Whether to mark the detected peaks in the figure.
16 %> @param flag_print_peaks =~isempty(peakd) Whether to print detected peaks on the command line window.
17 %> @param flag_text =0 Whether to write peak wavenumbers besize the "x"'s
18 function draw_stacked(x, histss, no_informative, colors, x_hint, hint, peakd, flag_trace_minalt, flag_draw_peaks, flag_print_peaks, flag_text)
19 fig_assert();
20 if ~exist('x_hint', 'var') || isempty(x_hint)
21  x_hint = x;
22 end;
23 if ~exist('hint', 'var') || isempty(hint)
24  hint = [];
25 end;
26 if ~exist('colors', 'var') || isempty(colors)
27 % colors = {[.8, 0, 0], [.9, .2, .2], .7*[1, 1, 1], .85*[1, 1, 1]};
28  colors = {[], .85*[1, 1, 1]};
29 end;
30 % checks colors a bit
31 no_colors = numel(colors);
32 if no_colors == 3 && ~isempty(colors{1})
33  irerror('If the number of colors passed is 3, the first element must be empty!');
34 end;
35 
36 if ~exist('no_informative', 'var') || isempty(no_informative)
37  no_informative = Inf;
38 end;
39 if ~exist('peakd', 'var') || isempty(peakd)
40  peakd = [];
41 end;
42 if ~exist('flag_trace_minalt', 'var') || isempty(flag_trace_minalt)
43  flag_trace_minalt = ~isempty(peakd);
44 end;
45 if ~exist('flag_draw_peaks', 'var') || isempty(flag_draw_peaks)
46  flag_draw_peaks = ~isempty(peakd);
47 end;
48 if ~exist('flag_print_peaks', 'var') || isempty(flag_print_peaks)
49  flag_print_peaks = ~isempty(peakd);
50 end;
51 
52 if ~exist('flag_text', 'var') || isempty(flag_text)
53  flag_text = 0;
54 end;
55 
56 no_hists = size(histss, 1);
57 no_informative = min(no_informative, no_hists);
58 
59 [cm, leg_cm, leg_la] = colors2map(colors, no_hists, no_informative);
60 
61 
62 %==============
63 % Hint curve
64 ymax = max(sum(histss, 1));
65 
66 if ~isempty(hint)
67  draw_hint_curve(x_hint, hint/max(hint)*ymax);
68 end;
69 
70 
71 %==============
72 % Main drawing
73 bar(x, histss', 'stacked', 'LineStyle', 'none');
74 hold on;
75 colormap(gca(), cm);
76 
77 % Legends
78 nl = numel(leg_la);
79 for i = 1:nl
80  h(i) = plot_marker(leg_cm(i, :), 15);
81 end;
82 legend(h, leg_la);
83 
84 
85 %==============
86 % The peaks
87 flag_bother_peaks = ~isempty(peakd) && (flag_print_peaks || flag_draw_peaks);
88 if flag_bother_peaks
89  y = sum(histss(1:no_informative, :), 1);
90  peakd = peakd.boot(x, y);
91  idxs_peaks = peakd.use([], y);
92 
93  if flag_draw_peaks
94  draw_peaks(x, y, idxs_peaks, flag_text);
95  end;
96 
97  if flag_print_peaks
98  fprintf('---------------- Peaks %s -----------------\n', '');
99  print_peaks(x, idxs_peaks);
100  end;
101 
102  % Plots "minimum altitude" line
103  if flag_trace_minalt
104  C = [.3, .3, .3];
105  draw_threshold_line(x, peakd.minalt, [], C);
106  end;
107 end;
108 
109 
110 % Formatting
111 format_frank();
112 format_xaxis(x);
113 ylabel('Hits');
114 
115 
116 set(gca, 'Ylim', [0, ceil(ymax*1.025)]);
117 
118 
119 
120 
121 %===========================================================================================================================================
122 function h = plot_marker(color, markersize)
123 h = plot(-1000, 0, 'LineStyle', 'none', 'Marker', 's', 'MarkerSize', markersize, 'Color', color, 'MarkerFaceColor', color);
function draw_peaks(in x, in y, in indexes, in flag_text, in color, in marker, in markersize)
function colors2map(in colors, in no_hists, in no_informative)
function irerror(in s)
function draw_hint_curve(in x, in y, in color)
function draw_threshold_line(in x, in y, in width, in color)
function plot_marker(in color, in markersize)
function format_frank(in F, in scale, in handles)
function fig_assert()
function draw_stacked(in x, in histss, in no_informative, in colors, in x_hint, in hint, in peakd, in flag_trace_minalt, in flag_draw_peaks, in flag_print_peaks, in flag_text)
function format_xaxis(in par)