Reputation: 7137
In MATLAB, is it possible to quickly/concisely increase the default padding around data in plots? In other words, I don't want the data to be too close to the axes.
Upvotes: 2
Views: 387
Reputation: 71
For a Matlab version recent enough, you can use the axis padded
command after your plots.
Upvotes: 1
Reputation: 2854
This approach is similar to @jodag's excellent answer and is entirely my preference. Posting this based on OP's request in the comments. I have no doubt there may be more efficient ways of doing this.
Key Idea: Automate use of xlim
and ylim
.
Minimal working example:
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
Other ways to automate this using these properties:
h = plot()
and modify propertiesset
, get
, and gca
commands. No doubt there are other approaches still.
Upvotes: 2
Reputation: 22314
If simply padding the existing axis is sufficient then the following should work. Say you want to add 10% to each side.
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);
Upvotes: 3