How to remove the margins of a plot
이전 댓글 표시
Hi there,
I have created a plot with the blow code, but there are still some additional margins on the left and right, could you tell me how to remove them?
I have tried it with setting the gca position, but it only works for the up and down side.
Here is the code I used:
% Data
xData = [0;42.5;0;-42.5];
yData = [42.5;0;-42.5;0];
zData = [0.5695;0.1766;-0.2984;-0.0129];
minFilterPressure = min(zData);
maxFilterPressure = max(zData);
% Set up fittype and options.
ft = 'biharmonicinterp';
% Fit model to data.
[fitresult, gof, output] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot the fit contour
figure(1)
plot(fitresult,[xData,yData],zData,'Style','Contour');
axisLimit = axis;
colormap(jet)
patch([42.5*cos(0:0.01:0.5*pi) 42.5], [42.5*sin(0:0.01:0.5*pi) 42.5], [1 1 1])
patch([42.5*cos(0.5*pi:0.01:pi) -42.5], [42.5*sin(0.5*pi:0.01:pi) 42.5], [1 1 1])
patch([42.5*cos(pi:0.01:1.5*pi) -42.5], [42.5*sin(pi:0.01:1.5*pi) -42.5], [1 1 1])
patch([42.5*cos(1.5*pi:0.01:2*pi) 42.5], [42.5*sin(1.5*pi:0.01:2*pi) -42.5], [1 1 1])
axis equal
title('Side1','FontSize',12,'FontWeight','bold')
text((axisLimit(2) + 5),0,'Side2','VerticalAlignment','middle','HorizontalAlignment','center','Fontsize',12,'FontWeight','bold','Rotation',-90);
xlabel('Side3','FontSize',12,'FontWeight','bold')
ylabel('Side4','FontSize',12,'FontWeight','bold')
text((axisLimit(1)+10),(axisLimit(4)-10),num2str(24),'Fontsize',12,'FontWeight','bold')
xticks(-50:10:50)
yticks(-50:10:50)
set(gca, 'Position', [0,0.1,1,0.85])
set(gcf,'PaperPositionMode','auto');
Here is the generated plot:

댓글 수: 3
Walter Roberson
2020년 6월 25일
Look at the axes properties InnerPosition and OuterPosition
Hao Shi
2020년 6월 25일
답변 (1개)
Deepak Meena
2020년 9월 24일
Hi Hao Shi,
Add these line of code to your answer :
set(gca, 'Position', [0.02,0.1,1,0.82])
set(gcf,'OuterPosition',[50 50 680 700]);
ax = gca;
outerpos = ax.OuterPosition;
ti = ax.TightInset;
left = outerpos(1) + ti(1);
bottom = outerpos(2) + ti(2);
ax_width = outerpos(3) - ti(1) - ti(3);
ax_height = outerpos(4) - ti(2) - ti(4);
ax.Position = [left bottom ax_width ax_height];
For more details about the properties of axes , refer to this document
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!