Save Figure at Specific Size and Resolution

Use Screen Size and Resolution

To print or save figures that are the same size as the figure on the screen, ensure that the PaperPositionMode property of the figure is set to 'auto' before printing. To generate output that matches the on-screen size in pixels, include the '-r0' resolution option when using the print function.

Note

Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead, for example, set(fig,'PaperPositionMode','auto').

bar([1 10 7 8 2 2 9 3 6])
fig = gcf;
fig.PaperPositionMode = 'auto';
print('ScreenSizeFigure','-dpng','-r0')

Expand Figure to Fill Page

To print or save a figure that fills the page, use print with either the '-fillpage' or '-bestfit' option. Both options are valid only when printing a figure to a printer or saving it to a paged format (PDF and full page PostScript®).

  • The '-fillpage' option maximizes the size of the figure to fill the page and leaves a .25 inch page margin. The tick marks, layout, and aspect ratio of the figure might change.

  • The '-bestfit' option maximizes the size of the figure to fill the page, but preserves the aspect ratio of the figure. The figure might not fill the entire page. This option leaves a minimum page margin of .25 inches.

This table shows an example of each option and the resulting output size.

Fill Page Option Best Fit Option
bar([1 10 7 8 2 2 9 3 6])
print('-fillpage','FillPageFigure','-dpdf')
bar([1 10 7 8 2 2 9 3 6])
print('-bestfit','BestFitFigure','-dpdf')

Use Specific Dimensions

To save or print a figure with specific dimensions, set the PaperPosition property of the figure to the desired dimensions. The PaperPosition property affects the size of saved and printed figures, but does not affect the size of the figure on the display. Set the property to a four-element vector of the form [left bottom width height].

  • left and bottom values — Control the distance from the lower left corner of the page to the lower left corner of the figure. These values are ignored when saving a figure to a nonpage format, such as a PNG or EPS format.

  • width and height values — Control the figure dimensions. The dimensions include the entire figure window except for the frame, title bar, menu bar, and any tool bars. If the width and height values are too large, then the figure might not reach the specified size. If the figure does not reach the specific size, then any UI components on the figure, such as uicontrols or a uitable, might not save or print as expected.

For example, save the figure with 6-by-3 inch dimensions using screen resolution.

Note

Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead, for example, set(fig,'PaperUnits','inches').

bar([1 10 7 8 2 2 9 3 6])
fig = gcf;
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 6 3];
print('5by3DimensionsFigure','-dpng','-r0')

Preserve Axis Limits and Tick Values

If the size of the saved or printed figure is different from the size on screen, the axis limits and tick values can change to accommodate the new size. To keep the axis limits and tick values from changing, set the tick value mode and limit mode properties for the axes to 'manual'.

Note

Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead, for example, set(ax,'XTickMode','manual').

bar([1 10 7 8 2 2 9 3 6])
ax = gca; 
ax.XTickMode = 'manual';
ax.YTickMode = 'manual';
ax.ZTickMode = 'manual';
ax.XLimMode = 'manual';
ax.YLimMode = 'manual';
ax.ZLimMode = 'manual';

fig = gcf;
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 6 3];
print('SameAxisLimits','-dpng','-r0')

See Also

|

Related Topics