Do other options exist when applying marker face colors to a gplotmatrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm implementing a gplotmatrix where the need to add marker face colors is needed for visual engancement. In the process of doing this, I've come up with an approach that works, with a caveat. In the following code, I've had to flip the order of elements pertaining to the variable newDefaultColors to ensure the marker colors and face colors are identical.
% Close all open figures, clear all workspace variables, and clear the command window
close all;
clear all; %#ok<CLALL>
clc;
% Load discrim variables into workspace
load discrim;
% Get the initial set of default plot colors
initialColorOrder = get(gca,'ColorOrder');
% Close the previously opened figure
close all;
% Create list selection dialog box
listdlg = menu('Which ColorOrder do you want?', 'random', 'hsv', 'hot', 'cool', 'pink');
% Ensure the number of data sets is the length of the unique groups
numberOfDataSets = length(unique(group));
% Create a new colormap that will define the new default color order property.
switch listdlg
case 1
newDefaultColors = rand(numberOfDataSets, 3);
case 2
newDefaultColors = hsv(numberOfDataSets);
case 3
newDefaultColors = hot(numberOfDataSets);
case 4
newDefaultColors = cool(numberOfDataSets);
otherwise
newDefaultColors = pink(numberOfDataSets);
end
% Flip the new default colors prior to adding marker face colors to plots
Marker_Face_Colors = flip(newDefaultColors);
% Apply the new default colors to the current axes
set(gca, 'ColorOrder', newDefaultColors);
% Now get the new set of default plot colors
newColorOrder = get(gca,'ColorOrder');
% Plot is created correctly with the following code
[h, ax, bigax] = gplotmatrix(ratings(:, 1:2), ratings(:, [4 7]), group, newColorOrder, 'o', 10, 'on', '', categories(1:2,:), categories([4 7],:));
% Turn on the X,Y grids for all 4 plots
ax(1,1).XGrid = 'on';
ax(1,1).YGrid = 'on';
ax(1,2).XGrid = 'on';
ax(1,2).YGrid = 'on';
ax(2,1).XGrid = 'on';
ax(2,1).YGrid = 'on';
ax(2,2).XGrid = 'on';
ax(2,2).YGrid = 'on';
% Apply marker face colors to the upper left corner plot
hobj11 = findobj(ax(1,1), 'Type', 'line');
for jj = 1:size(Marker_Face_Colors, 1)
hobj11(jj).MarkerFaceColor = Marker_Face_Colors(jj,:);
end
% Apply marker face colors to the upper right corner plot
hobj12 = findobj(ax(1,2), 'Type', 'line');
for jj = 1:size(Marker_Face_Colors, 1)
hobj12(jj).MarkerFaceColor = Marker_Face_Colors(jj,:);
end
% Apply marker face colors to the upper left corner plot
hobj21 = findobj(ax(2,1), 'Type', 'line');
for jj = 1:size(Marker_Face_Colors, 1)
hobj21(jj).MarkerFaceColor = Marker_Face_Colors(jj,:);
end
% Apply marker face colors to the upper left corner plot
hobj22 = findobj(ax(2,2), 'Type', 'line');
for jj = 1:size(Marker_Face_Colors, 1)
hobj22(jj).MarkerFaceColor = Marker_Face_Colors(jj,:);
end
I'm not sure why I need to do this. Or if it's a good implementation going forward.
Do other options exist when applying marker face colors to a gplotmatrix?
댓글 수: 2
Walter Roberson
2019년 8월 25일
A sightly different approach that is not any better but makes the code more compact:
hobjs = [findobj(ax(1,1), 'Type', 'line'), findobj(ax(1,2), 'Type', 'line'), findobj(ax(2,1), 'Type', 'line'), findobj(ax(2,2), 'Type', 'line')];
for jj = 1 : size(hobjs,1)
set(hobjs(j,:) 'MarkerFaceColor', Marker_Face_colors(jj,:));
end
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!