2017-02-08 4 views
1

図の境界線の外に余分な空白を含んでいないmatlabの図が欲しいです。私は別のものを試しました。たとえば、余分な空白がない状態でmatlabの図形を作ることができません

set(gca,'LooseInset',get(gca,'TightInset')) 

ただし、z軸ラベルが削除されます。ユーザが作成した関数 "spaceplots"も働きません(何も返しません)。 MathWorks(https://se.mathworks.com/help/matlab/creating_plots/save-figure-with-minimal-white-space.html)によって記述された方法も機能しません。

これはどのようにすることができますか?

答えて

0

次の操作を実行できます。

% creat some 3D plot: 
x = 1:0.1:10; 
y = x; 
[X,Y] = meshgrid(x,y); 
f = @(x,y) sin(x).*cos(y); 
Z = f(X,Y); 
surf(X,Y,Z) 
xlabel('Xsomething') 
ylabel('Ysomething') 
zlabel('Zsomething') 

%%% here it starts: %%% 
ax = gca; 
post = findall(ax,'Type','Text'); % get all text handles 
p = zeros(numel(post),2); 
% collect all the position vectors: 
for k = 1:numel(post) 
    post(k).Units = 'normalized'; % set units to the normelized figure units 
    % the 'position' of the text is relative to the axes, so we convert it 
    % to the figure units: 
    p(k,:) = post(k).Position(1:2)+ax.Position(1:2); 
end 
% find the most left and bottom items, 
% and move them to the borders of the figure: 
ax.Position(1:2) = min(p); 
% fill the rest of the figure with th axes: 
ax.Position(3:4) = 1-ax.Position(1:2); 

前:

​​3210

後:

after

+0

"ax.Position(1:2)= min(p);":A(:) = Bの代入でAとBの要素数が同じでなければなりません。 – Yoda

+0

Btwなので、これで白い空白が図形で埋められます。これは私がスクリプトで定義したフィギュアの寸法に影響を及ぼしますか? – Yoda

+0

@ Yoda、私は何のエラーもありません。上記のコードをMatlabの新鮮なセッションで実行しようとしましたか?結果として得られる 'p'の大きさはどれくらいですか? – EBH

関連する問題