Save plot with minimal white space without removing part of the figure
Mostra commenti meno recenti
In order to save MATLAB plots with minimal white space I have been using the code from this resource,with the code copied below.
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];
However, part of the figure is now cut off (the 0 on the axis bar). Is there a simple solution to this problem?

Edit: also there is still white space at the left and right edges. It is hard to see extra white space so I also attached the image. Of course I can remove this manually, but since I am processing many images it would be much faster to do it automatically.
Thanks!
5 Commenti
Adam Danz
il 11 Giu 2019
I could not recreate the problem. When I add a colorbar either before or after the resize, the upper and lower ends are not cut off.
Is there another section of your code that sets axis to equal or square?
Vivek Gupta
il 17 Giu 2019
Adam Danz
il 17 Giu 2019
I ran all 3 sections of your code from the comment above and still cannot recreate the problem. I'm using r2019a.

Vivek Gupta
il 17 Giu 2019
Risposta accettata
Più risposte (1)
Brad Porter
il 12 Giu 2020
1 voto
If you are not trying to develop a flexible application and just need a quick solution, just adjust the numbers in the following:
figure()
set(gca,'position',[0.07 0.07 0.92 0.88]);
done.
1 Commento
Hai-Po Chan
il 29 Set 2022
This works great for me. Thank you!
Categorie
Scopri di più su Graphics Object Properties in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
