How to remove the margins of a plot
247 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321682/image.jpeg)
回答(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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!