How to remove the margins of a plot

조회 수: 274 (최근 30일)
Hao Shi
Hao Shi 2020년 6월 25일
답변: Deepak Meena 2020년 9월 24일
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
Hao Shi
Hao Shi 2020년 6월 25일
Dear Walter and KSSV,
Thank you very much for your kind suggestions.
For Walter's suggestion, I have tried to set both of the gca position and outerPosition, but there seems no big changes, the left and right margins are still there, the parameters I set are listed below. Could you help me to find where the problem is?
set(gca, 'Position', [-0.1,0.1,1.2,0.85])
set(gca, 'OuterPosition', [0,0,1,1])
For KSSV's suggestion, the command is valid since the version 2020a, which does not work on my version.

댓글을 달려면 로그인하십시오.

답변 (1개)

Deepak Meena
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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by