Automatically remove white space from figure

547 Ansichten (letzte 30 Tage)
RuiQi
RuiQi am 16 Jul. 2017
Kommentiert: Klas Lindgren am 25 Apr. 2023
How do I remove the white space from the figures ? I don't want to have to save the image then manually crop it.
Instead of Matlab's dumb figure it would be something like
smart_figure('NoWhiteSpace');
plot(..);
or
figure;
plot(..);
smart_clean('NoWhiteSpace');
Is there such a function ?

Antworten (5)

Pankaj
Pankaj am 7 Okt. 2018

Image Analyst
Image Analyst am 3 Dez. 2020
Try the new exportgraphics() function.
  4 Kommentare
Ritesh Chandra Tewari
Ritesh Chandra Tewari am 15 Jul. 2021
It worked for me. Thanks!
Klas Lindgren
Klas Lindgren am 25 Apr. 2023
Life-saver! Thanks!

Melden Sie sich an, um zu kommentieren.


Surender Raj
Surender Raj am 3 Dez. 2020
This problem can be addressed manually in Export setup. Once figures are done File--> Export setup --> Size --> Check expand axes to fill figures.
  2 Kommentare
Tong Zhao
Tong Zhao am 29 Jul. 2022
Thank you, it worked, but I have an additional question: when the axes fills the figure, it breaks the aspect ratio of the content. How can I make sure that the aspect ratio stays the same when filling?
Image Analyst
Image Analyst am 29 Jul. 2022
What is in your axes? Line plots? Images? If it's images, use
axis('on', 'image');
to make sure the aspect ratio is correct.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 16 Jul. 2017
Attach images showing what you have and what you want.
You can change the amount of gray padding about your axes by setting the Position property of the axes.

Julia
Julia am 11 Jun. 2021
I find the following really useful:
First, assemble your figure as you normally would. Then, try this:
I0 = getframe;
imwrite(I0.cdata, fullfile(path,'image.png'))
I have the impression that it needs some time for saving, so if used in code where stuff happens after this line it can sometimes give weird results. If you have the figure ready and then execute the code from the command line, it normally works beautifully.

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by