How can i reduce the size of the legend and increase the size of the plot figure?

55 ビュー (過去 30 日間)
Hello every one,
I am trying to reduce the size of the legend. Is it possible to reduce the size of the legend and at the same time increase the size of the subplots. Please help me. My code is as follows:
Z = readtable('Trail.xlsx') ;
data = table2array(Z) ;
subplot(4,3,1)
plot(data(:,1), data(:,2), 'ks', 'MarkerSize',6);
hold on
plot(data(:,85), data(:,86), 'kv', 'MarkerSize',4);
hold on
plot(data(:,87), data(:,88), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,6), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,8), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,10), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,12), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,14), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.1])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,2)
plot(data(:,3), data(:,4), 'ks', 'MarkerSize',6);
hold on
plot(data(:,89), data(:,90), 'kv', 'MarkerSize',4);
hold on
plot(data(:,91), data(:,92), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,7), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,9), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,11), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,13), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,15), 'Color', color, 'linewidth', 2);
hold off
grid on
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,4)
plot(data(:,16), data(:,17), 'ks', 'MarkerSize',6);
hold on
plot(data(:,18), data(:,19), 'kv', 'MarkerSize',4);
hold on
plot(data(:,20), data(:,21), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,29), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,31), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,33), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,35), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,37), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,5)
plot(data(:,22), data(:,23), 'ks', 'MarkerSize',6);
hold on
plot(data(:,24), data(:,25), 'kv', 'MarkerSize',4);
hold on
plot(data(:,26), data(:,27), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,30), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,32), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,34), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,36), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,38), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,7)
plot(data(:,39), data(:,40), 'ks', 'MarkerSize',6);
hold on
plot(data(:,41), data(:,42), 'kv', 'MarkerSize',4);
hold on
plot(data(:,43), data(:,44), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,52), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,54), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,56), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,58), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,60), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,8)
plot(data(:,45), data(:,46), 'ks', 'MarkerSize',6);
hold on
plot(data(:,47), data(:,48), 'kv', 'MarkerSize',4);
hold on
plot(data(:,49), data(:,50), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,53), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,55), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,57), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,59), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,61), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,10)
plot(data(:,62), data(:,63), 'ks', 'MarkerSize',6);
hold on
plot(data(:,64), data(:,65), 'kv', 'MarkerSize',4);
hold on
plot(data(:,66), data(:,67), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,75), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,77), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,79), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,81), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,83), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,3,11)
plot(data(:,68), data(:,69), 'ks', 'MarkerSize',6);
hold on
plot(data(:,70), data(:,71), 'kv', 'MarkerSize',4);
hold on
plot(data(:,72), data(:,73), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,76), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,78), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,80), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,82), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,84), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
fig = gcf;
fig.Position(3) = fig.Position(3) + 250;
legend('legend1', 'legend2', 'legend3', 'legend4', 'legend5', 'legend6', 'legend7',...
'legend8', 'Location', 'northeastoutside', 'FontSize',10);
Lgnd = legend('show');
lgd.FontSize = 15;
Lgnd.Position(1) = 0.8;
Lgnd.Position(2) = 0.4;
hsp4369 = subplot(4,3,[6 9]);
% get(hsp2448)
hsp4369.Visible = 'off';
Lgnd.Position = hsp4369.Position+[0 +0.1 0 0.01];
sgtitle(["XYZ"])
x0=12;
y0=2;
width=1200;
height=760;
set(gcf,'position',[x0,y0,width,height])
set(gcf,'PaperOrientation','landscape');

採用された回答

Jasvin
Jasvin 2023 年 2 月 6 日
編集済み: Jasvin 2023 年 2 月 6 日
I tried reproducing your plot, tinkered with the settings and was able to get the following plot,
Does this look closer to what you were trying to achieve?
  2 件のコメント
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2023 年 2 月 6 日
Hello @Jasvin,
Thank you for the reply. Cam you please tell me how can you edited this?
Jasvin
Jasvin 2023 年 2 月 6 日
I edited your code to look like the following,
% Plot Code
Z = readtable('Trail.xlsx') ;
data = table2array(Z) ;
subplot(4,2,1)
plot(data(:,1), data(:,2), 'ks', 'MarkerSize',6);
hold on
plot(data(:,85), data(:,86), 'kv', 'MarkerSize',4);
hold on
plot(data(:,87), data(:,88), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,6), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,8), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,10), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,12), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,14), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.1])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,2)
plot(data(:,3), data(:,4), 'ks', 'MarkerSize',6);
hold on
plot(data(:,89), data(:,90), 'kv', 'MarkerSize',4);
hold on
plot(data(:,91), data(:,92), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,7), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,9), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,11), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,13), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,5), data(:,15), 'Color', color, 'linewidth', 2);
hold off
grid on
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,3)
plot(data(:,16), data(:,17), 'ks', 'MarkerSize',6);
hold on
plot(data(:,18), data(:,19), 'kv', 'MarkerSize',4);
hold on
plot(data(:,20), data(:,21), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,29), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,31), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,33), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,35), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,37), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,4)
plot(data(:,22), data(:,23), 'ks', 'MarkerSize',6);
hold on
plot(data(:,24), data(:,25), 'kv', 'MarkerSize',4);
hold on
plot(data(:,26), data(:,27), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,30), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,32), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,34), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,36), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,28), data(:,38), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,5)
plot(data(:,39), data(:,40), 'ks', 'MarkerSize',6);
hold on
plot(data(:,41), data(:,42), 'kv', 'MarkerSize',4);
hold on
plot(data(:,43), data(:,44), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,52), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,54), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,56), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,58), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,60), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,6)
plot(data(:,45), data(:,46), 'ks', 'MarkerSize',6);
hold on
plot(data(:,47), data(:,48), 'kv', 'MarkerSize',4);
hold on
plot(data(:,49), data(:,50), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,53), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,55), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,57), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,59), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,51), data(:,61), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,7)
plot(data(:,62), data(:,63), 'ks', 'MarkerSize',6);
hold on
plot(data(:,64), data(:,65), 'kv', 'MarkerSize',4);
hold on
plot(data(:,66), data(:,67), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,75), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,77), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,79), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,81), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,83), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
subplot(4,2,8)
plot(data(:,68), data(:,69), 'ks', 'MarkerSize',6);
hold on
plot(data(:,70), data(:,71), 'kv', 'MarkerSize',4);
hold on
plot(data(:,72), data(:,73), 'k*', 'MarkerSize',4);
hold on
str = '#D95319';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,76), 'Color', color, 'linewidth', 2);
hold on
str = '#EDB120';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,78), 'Color', color, 'linewidth', 2);
hold on
str = '#7E2F8E';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,80), 'Color', color, 'linewidth', 2);
hold on
str = '#77AC30';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,82), 'Color', color, 'linewidth', 2);
hold on
str = '#4DBEEE';
color = sscanf(str(2:end),'%2x%2x%2x',[1 3])/255;
plot(data(:,74), data(:,84), 'Color', color, 'linewidth', 2);
hold off
grid on
xlim([0 0.35])
xlabel('X');
ylabel('Y');
title('x = 105mm')
% Configuring the Legend
% Box = Off, turns off the unnecessarily padded box from the legend
% Position = [X Position, Y Position, Height, Width]
legend('legend1', 'legend2', 'legend3', 'legend4', 'legend5', 'legend6', 'legend7',...
'legend8', 'Position', [0 0.75 0.1 0.25], 'FontSize', 10, 'Box', 'off');
For further reference, if you want to find out properties like these, you can refer to the legend documentation.
Also, as Navneet has suggested in the alternate answer, you can use the "Edit Plot" tool to move the plots around including the legend and then use the "Property Inspector" within the Plot to find out its properties which you can then cross-reference from the Documentation and finally convert that to code.
So in this case, I moved the legend to its desired location via "Edit Plot" and then inspected its Position property and then put those same values in the code as you can see in the final line.

サインインしてコメントする。

その他の回答 (2 件)

NAVNEET NAYAN
NAVNEET NAYAN 2023 年 2 月 6 日
After running the code, in the figure window having the subplots, there is an arrow for edit plot as shown in the attached figure. After selecting the arrow you can change the size of the plots by selecting and dragging the boundaries of subplots manually, as per your requirement, as done for an example shown in the figure. In the figure, we have changed the size of first two subplots and legend for example.

Smit
Smit 2023 年 2 月 6 日
Hi,
I understand you want to change the size of the legend and subplots in your plot.
To change the size of the objects in your plot you can use the “set” function to change the “position” property of the legend and axes objects returned by the “legend” and “subplot” functions respectively.
You can refer to the following example
lgnd = legend('legend1', 'legend2', 'legend3', 'legend4', 'legend5', 'legend6', 'legend7',...
'legend8', 'Location', 'northeastoutside', 'FontSize',10);
% Use the “set” function to change the size of legend
set(lgnd, 'position', [0.8 0.4 width height]);
Similarly, for the subplots
ax = subplot(4,3,1)
% Use the “set” function to change the size of subplot
% To preserve the position of the subplot you copy the existing value of first 2 values in the
% "Position” vector of the Axes object
set(ax, 'position', [ax.Position(1) ax.Position(2) width height]);
In both cases, you can set the width and height according to your requirements.
In general, you can change the “position” using the “set” function in the following manner
set(object_handle, 'position', [x0 y0 width height]);

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by