Scatter plot legend marker size is huge
2 ビュー (過去 30 日間)
古いコメントを表示
The legend icons in my scatter plot are huge in the saved PDF (they look fine in the Matalb figure pop-up window). I tried some of the solutions I found in the MATLAB Answers forum and StackExchange, but no luck.
Self-contained code is below; any help is appreciated.
%%% dummy data and plots
x = randi([1,100],50,1);
y = randi([1,25],50,1);
g = randi([1,4],50,1);
allData = array2table([x y g]);
allData.Properties.VariableNames = {'x', 'y', 'g'};
nplts = 12;
colors = {'black', 'magenta', 'blue', 'green', 'cyan'};
for ii = 1:nplts
ax(ii) = subplot(nplts/3, 3, ii);
groups = unique(allData.g);
% note gscatter doesn't work well here because real data has
% NaNs mixed in that I am deleting, which is why I am looping
% through the groups
for jj = 1:length(groups)
tempGroup = groups(jj);
tempTable = allData(allData.g == tempGroup, :);
xy = [tempTable.x tempTable.y]; % do this to remove NaN in real data, not in this pretend data
xy(any(isnan(xy), 2), :) = []; % do this to remove NaN in real data, not in this pretend data
mycolor = colors{jj};
scatter(xy(:,1), xy(:,2), 8, mycolor, 'HandleVisibility', 'off')
hold on
label = char(strcat('Group =', num2str(tempGroup), {' '}, 'n=', num2str(length(xy))));
scatter([1,1], [1,1], NaN, mycolor, 'DisplayName', label); % dummy plot for legend
end
box on; grid on
set(gcf, 'Resize', 'off')
xlabel('x', 'FontSize', 10)
ylabel('y', 'FontSize', 10)
plotname = char(strcat('My_Plot', {' '}, num2str(ii)));
title(plotname, 'FontSize', 10, 'Interpreter', 'None')
lgd = legend;
lgd.FontSize = 6; lgd.Location = 'southoutside';
H = findobj('type', 'legend');
icons = findobj(H, 'type', 'patch'); % doesn't work
%icons = findobj(H, '-property', 'Marker', '-and', '-not', 'Marker', 'none'); % also doesn't work
set(icons, 'MarkerSize', 1);
end
linkaxes(ax, 'xy')
%%% save to pdf
h = gcf;
set(h, 'PaperPositionMode', 'auto')
set(h, 'PaperUnits', 'inches')
set(h, 'PaperSize', [11, 17])
set(h, 'PaperPosition', [0, 0, 11, 17])
print('myfigure', '-r300', '-dpdf')
0 件のコメント
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!