如果简单地填充现有轴就足够了,那么以下应该可以工作。假设您想每边添加 10%。
plot(...);
scale = 1.1;
ax = axis();
xc = 0.5 * (ax(1)+ax(2));
yc = 0.5 * (ax(3)+ax(4));
c = [xc,xc,yc,yc];
axis(scale * (ax - c) + c);
这种方法类似于@jodag的优秀answer,并且完全是我的偏好。根据评论中OP的要求发布此内容。我毫不怀疑可能有更有效的方法来做到这一点。
关键思想: 自动使用
xlim
和 ylim
。
最小工作示例:
d = 0.10; % 10 percent
c = [1-d 1+d];
X = 5 + 5*rand(10,2);
plot(X(:,1),X(:,2),'rs')
Xrng = xlim;
Yrng = ylim;
xlim(c.*Xrng); % Adjust X Range
ylim(c.*Yrng); % Adjust Y Range
使用这些属性实现自动化的其他方法:
h = plot()
并修改属性set
、get
和 gca
命令。 毫无疑问还有其他方法。
对于足够新的 Matlab 版本,您可以在绘图后使用
axis padded
命令。