IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
data_draw_scatter_3d.m
Go to the documentation of this file.
1 %>@ingroup datasettools
2 %>@file
3 %>@brief Draws 3-D scatter plot
4 
5 %> @param data dataset
6 %> @param idx_fea What features to use. Numbers point to columns in @c data.X
7 %> @param confidences a list of percentages (]0, 1[) for the confidence ellipses
8 %> @param textmode=0
9 %> @arg 0 - no text anotation
10 %> @arg 1 - annotates "obsnames"
11 %> @arg 2 - annotates "groupcodes"
12 %> @return <em>[data]</em>
13 %> @return <em>[data, handles]</em>. handles: handles for the legends
14 function varargout = data_draw_scatter_3d(data, idx_fea, confidences, textmode)
15 global FONT FONTSIZE SCALE;
16 
17 
18 if ~exist('confidences', 'var')
19  confidences = [];
20 end;
21 
22 if ~exist('textmode', 'var')
23  textmode = 0;
24 end;
25 
26 if numel(idx_fea) < 3
27  irerror('idx_fea must have 3 elements!');
28 end;
29 if any(idx_fea > data.nf)
30  irerror(sprintf('Dataset has only %d feature(s)!', data.nf));
31 end;
32 
33 pieces = data_split_classes(data);
34 
35 no_classes = size(pieces, 2);
36 for i = 1:no_classes
37  X = pieces(i).X(:, idx_fea([1 2 3]));
38 
39  hh = plot3(X(:, 1), X(:, 2), X(:, 3), 'Color', find_color(i), 'Marker', find_marker(i), 'MarkerSize', find_marker_size(i), 'MarkerFaceColor', find_color(i), 'LineStyle', 'none');
40  handles(i) = hh(1);
41  hold on;
42 
43  if textmode == 1 && ~isempty(pieces(i).obsnames)
44  text(X(:, 1), X(:, 2), X(:, 3), pieces(i).obsnames); %, 'FontName', FONT, 'FontSize', FONTSIZE*.7);
45  elseif textmode == 2 && ~isempty(pieces(i).groupcodes)
46  text(X(:, 1), X(:, 2), X(:, 3), pieces(i).groupcodes); %, 'FontName', FONT, 'FontSize', FONTSIZE*.7);
47  end;
48 
49 
50 
51  % ellipses
52  if ~isempty(confidences)
53  m = mean(X);
54  C = cov(X);
55  for j = 1:length(confidences)
56  error_ellipse(C, m, 'conf', confidences(j), 'Color', find_color(i));
57  end;
58  end;
59 end
60 
61 mins = min(data.X(:, idx_fea), [], 1);
62 maxs = max(data.X(:, idx_fea), [], 1);
63 lens = maxs-mins;
64 K = 0.05;
65 xlim([mins(1)-lens(2)*K, maxs(1)+lens(1)*K]);
66 ylim([mins(2)-lens(2)*K, maxs(2)+lens(2)*K]);
67 zlim([mins(3)-lens(3)*K, maxs(3)+lens(3)*K]);
68 
69 
70 feanames = data.get_fea_names(idx_fea);
71 xlabel(feanames{1});
72 ylabel(feanames{2});
73 zlabel(feanames{3});
74 
75 hleg = legend(handles, data_get_legend(data));
76 format_frank();
77 
78 if nargout <= 1
79  varargout = {data};
80 elseif nargout == 2
81  varargout = {data, handles};
82 end;
function find_marker(in i)
function find_color(in i)
function irerror(in s)
function find_marker_size(in i)
function data_get_legend(in data)
function data_draw_scatter_3d(in data, in idx_fea, in confidences, in textmode)
function data_split_classes(in data, in hierarchy)
function format_frank(in F, in scale, in handles)