How do I change the position of the axes permanently?
42 views (last 30 days)
Show older comments
Although I keep putting them on origin, the X and Y axes keep going down and left every time I plot a function. So I was wondering if I can change this permanently to have them always on the origin.
1 Comment
Jan
on 5 Jun 2021
What does "keep putting them on origin" mean? What is going to where? Which origin do you mean?
Can you post some code and a screen shot, which explains, what you want to achieve?
Answers (4)
John D'Errico
on 5 Jun 2021
Edited: John D'Errico
on 5 Jun 2021
There are some defaults you can set as defaults, but XAxisLocation and YAxisLocation do not appear to fall under the list of things I can set as defaults for the root. I assume that is because they are axis properties, not figure properties.
However, nothing stops you from writting a little helper function, thus...
function setAxesToOrigin
set(gca,'XAxisLocation','origin')
set(gca,'YAxisLocation','origin')
end
Then just execute that function after your plot is done.
0 Comments
dpb
on 5 Jun 2021
Taking a stab at the OP's meaning (thanks to the Crystal Ball having just been returned from the shop (yet) again...)
Try
set(groot,'defaultAxesXAxisLocation','origin')
set(groot,'defaultAxesYAxisLocation','origin')
0 Comments
Adam Danz
on 5 Jun 2021
You have to either hold the axes after setting the axis location or set the axis location after plotting.
ax = subplot(1,2,1);
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlim([-1,1])
ylim([-1,1])
hold on % <--------- hold axes
plot(rand(1,20)*2-1,rand(1,20)*2-1,'o')
or
ax = subplot(1,2,2);
plot(rand(1,20)*2-1,rand(1,20)*2-1,'o')
xlim([-1,1])
ylim([-1,1])
box off
ax.XAxisLocation = 'origin'; % <----- after plotting
ax.YAxisLocation = 'origin'; % <----- after plotting
0 Comments
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!