2017-02-08 1 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); 

전 :

before

후 :

after

+0

"ax.Position (1 : 2) = min (p);"에 대한 오류가 있습니다. 할당 A (:) = B에서 A와 B의 요소 수는 동일해야합니다. – Yoda

+0

Btw, 그래서 이것으로 공백이 그림으로 채워집니다. 이것이 제가 스크립트에서 정의한 Figure의 크기에 영향을 줍니까? – Yoda

+0

@ 요다, 나는 어떤 에러도 내지 않는다. 위의 코드를 Matlab의 새로운 세션에서 실행하려고 했는가? 어떤 크기의 결과'p'입니까? – EBH

관련 문제