どのようにしてsubplotでなるべく余白を少なくすることができますか?
103 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2015 年 12 月 11 日
回答済み: MathWorks Support Team
2015 年 12 月 11 日
どのようにしてsubplotでなるべく余白を少なくすることができますか?
以下のようなスクリプトで作成した Figure の上下左右の余白を可能な限り少なく方法を教えて下さい。
rect1 = [ 0, 0, 960, 650];
set(gcf, 'Position', rect1);
for i0=1:25;
subplot(5,5,i0);plot(randn(1,100))
end;
採用された回答
MathWorks Support Team
2015 年 12 月 11 日
subplot 関数では、縦横の軸数を基に、自動的にPosition (位置、サイズ) が決定されることになりますので、手動調節させる場合、 subplot 関数の変わりに、 Positionプロパティ付きの axes 関数を 利用する方法となります。
Position は、 1x4 のベクトルで定義し
[左下(x軸)の座標, 左下(y軸)の座標, 幅、 高さ] を 数字で表します。
(Default の単位は Normalize となります)
一例となりますが、5x5 = 25種類の Axes を配置する場合、下記のようなコマンドにて実現頂く事になってしまいます。
Position で指定する値は、適宜調節ください。
rect1 = [ 0, 0, 960, 650];
set(gcf, 'Position', rect1);
row = 5; % 列subplot数
col = 5; % 行subplot数
left_m = 0.02; % 左側余白
bot_m = 0.05; % 下側余白
ver_r = 1.1; % 縦方向余裕 (値が大きいほど各axes間の余白が大きくなる)
col_r = 1.2; % 横方向余裕 (値が大きいほど各axes間の余白が大きくなる)
for n =1:1:row*col
% Position は、各Axes に対し、 [左下(x), 左下(y) 幅, 高さ] を指定
ax(n) = axes('Position',...
[(mod(n-1,col))/col + left_m ,...
1-ceil(n/col)/(row) + bot_m ,...
1/(col*col_r ),...
1/(row*ver_r)-bot_m]...
);
plot(ax(n),1:500,randn(1,500));
legend(num2str(n))
end
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!