📄 plot_data.m
字号:
% plot_data(data, sampleLabels)%% The main function for plotting data generated by the GPCA algorithm.%% Can handle two or three dimensional data.%% Can also display a set of normal vectors on the same graph. Not all% normal vectors need to be computed; the number to be displayed must be% specified. Normal vectors will be rendered in order they are passed.%function pl = plot_data(data, sampleLabels, plotOutliers)if nargin<3 plotOutliers = true;end% Hold while drawing a bunch of elements to the current figure.originalHoldState = ishold;hold on;if ~exist('sampleLabels','var'), sampleLabels = ones(1,size(data,2));endgroupCount = max(sampleLabels);sampleCount = size(data,2);markers = '.ox+*svp^h<>'; markerCount = length(markers); markerIndex = 1;colors = 'rbgmcyk'; colorCount = length(colors); colorIndex = 1;if size(data,1) == 2 % Plot outliers if plotOutliers groupDataIndices = find(sampleLabels==-1); if ~isempty(groupDataIndices) pl = plot(data(1, groupDataIndices),data(2,groupDataIndices), '*k'); view(2); end end for groupIndex = 1:groupCount, groupDataIndices = find(sampleLabels == groupIndex); pl = plot(data(1, groupDataIndices),data(2,groupDataIndices), [markers(markerIndex) colors(colorIndex)]); % set(pl,'MarkerSize', 5); % Set the plot to the default 2D view. view(2); % Advance to the next color, and marker if all of the colors have % been used. colorIndex = colorIndex+1; if (colorIndex > colorCount), colorIndex = 1; markerIndex + 1; if (markerIndex > markerCount), markerIndex = 1; end; end; end xlabel('axis 1') ylabel('axis 2') elseif size(data,1) == 3 % Plot outliers if plotOutliers groupDataIndices = find(sampleLabels==-1); if ~isempty(groupDataIndices) pl = plot3(data(1, groupDataIndices),data(2,groupDataIndices),data(3,groupDataIndices), '*k'); set(pl,'MarkerSize', 10); view(3); camproj('orthographic'); end end for groupIndex = 1:groupCount, groupDataIndices = find(sampleLabels == groupIndex); pl = plot3(data(1, groupDataIndices),data(2,groupDataIndices),data(3,groupDataIndices), [markers(markerIndex) colors(colorIndex)]); set(pl,'MarkerSize', 10); % Set the plot to the default 3D view. view(3); % Set the camera projection type. % camproj('perspective'); camproj('orthographic'); % Advance to the next color, and marker if all of the colors have % been used. colorIndex = colorIndex+1; if (colorIndex > colorCount), colorIndex = 1; markerIndex + 1; if (markerIndex > markerCount), markerIndex = 1; end; end; end xlabel('axis 1') ylabel('axis 2') zlabel('axis 3') else warning('Sorry, data must be of dimension 2 or 3 to be displayed by plot_data.m') returnend% Restore original hold stateif ~originalHoldState, hold off;end% Resize the figure window so that it is more readily visible.set(0,'Units','pixels');temp = (get(0,'ScreenSize'));screenColumns = temp(3);screenRows = temp(4);figureFillRatio = [.8 .5]; % Fraction of the columns and rows to fill up.screenCenter = floor([screenColumns/2 screenRows/2]);cornerOffset = floor([screenColumns*figureFillRatio(1)/2 screenColumns*figureFillRatio(2)/2]);set(gcf,'Position',[screenCenter - cornerOffset, 2*cornerOffset]);%set(gcf,'MenuBar','none')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -