saveas for figures no longer works properly
8 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Dec 2017
Edited: MathWorks Support Team
on 13 Apr 2023
Why is "saveas" cutting off my figure and giving me a warning?
Warning: The figure is too large for the page and will be cut off. Resize the figure, adjust the output size by setting the figure's PaperPosition property, use the 'print' command with either the '-bestfit' or '-fillpage' options, or use the 'Best fit' or 'Fill page' options on the 'Print Preview' window.
Accepted Answer
MathWorks Support Team
on 13 Apr 2023
Edited: MathWorks Support Team
on 13 Apr 2023
To save large figures without them getting cut off:
The warning message is suggesting you use the "print" function instead of the "saveas" function. Setting the "resize" option in "print" with the '-bestfit' or '-fillpage' options will fix the sizing issue.
bestfit:
Maximize the size of the figure to fill the page, but preserve the aspect ratio of the figure. The figure might not fill the entire page. This option leaves a minimum page margin of .25 inches
fillpage:
Maximize the size of the figure to fill the page. Leaves a .25 inch margin on all sides of the page. The tick marks, layout, and aspect ratio of the figure might change.
If you prefer to use the "saveas" function, another method is to change the figure's PaperPositionMode to 'manual' and set the figure's PaperPosition as desired.
I have attached an M-file with an example explaining both of the above methods. Running the program will create PDF files that show the differences between executing each option.
You can also find more properties and functions related to saving figures in these links:
To change the default for "saveas" to not cut off large figures:
1. Set the default value of "PaperPositionMode" to 'manual'. This preference will persist across MATLAB sessions.
>> matlab.graphics.internal.setPrintPreferences('DefaultPaperPositionMode','manual')
2. Set the default "FigurePaperPositionMode" to 'manual' before creating the figures.
>> set(groot,'defaultFigurePaperPositionMode','manual')
Note: This will need to be executed again every time you open MATLAB. If you would like this to persist across MATLAB sessions, place the above line of code in your "startup.m" file.
If you do not have a startup.m file, create a "startup.m" file in a folder on the MATLAB search path.
For more options and details on the above see the two links below.
Details on saveas properties: https://www.mathworks.com/help/matlab/ref/saveas.html
Creating a "startup.m" file: https://www.mathworks.com/help/matlab/ref/startup.html
0 Comments
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!