I want to eliminate the margins of Axes, but it doesn't work.
22 views (last 30 days)
Show older comments
I tried to remove the left and right margins with the following code, but it did not work.
I have set the width of the OuterPosition minus the margins on both sides of the TightInset to the Position, but the left margin does not disappear. Why is this?
When I moved the plot with the mouse, it was exactly the same width as the figure.
In the attached image, the margins are colored for clarity.
plot(rand(1,20))
ax = gca;
ax.OuterPosition(1)=0;
ax.OuterPosition(3)=1;
ax.Position(3)=ax.OuterPosition(3)-ax.TightInset(1)-ax.TightInset(3);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/577097/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/577102/image.png)
0 Comments
Accepted Answer
More Answers (1)
Jan
on 8 Apr 2021
The "TightInset" includes the tick labels. See https://www.mathworks.com/help/matlab/creating_plots/automatic-axes-resize.html
Try to set the 'Position' property instead:
plot(rand(1,20))
figure('Color', 'y')
ax = gca;
ax.Position(1) = 0;
ax.Position(3) = 1;
See Also
Categories
Find more on Graphics Object Properties 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!