Clear Filters
Clear Filters

どのようにしてsub​plotでなるべく余​白を少なくすることが​できますか?

91 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 11 Dec 2015
どのようにしてsubplotでなるべく余白を少なくすることができますか?
以下のようなスクリプトで作成した Figure の上下左右の余白を可能な限り少なく方法を教えて下さい。
rect1 = [ 0, 0, 960, 650]; 
set(gcf, 'Position', rect1); 
for i0=1:25; 
subplot(5,5,i0);plot(randn(1,100))
end; 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Dec 2015
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 

More Answers (0)

Categories

Find more on 2 次元および 3 次元プロット in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!