Print figure or save to specific file format
Syntax
Description
print(
saves the current
figure to a file using the specified file format, such as
filename
,formattype
)print('BarPlot','-dpng')
. If the file name does not
include an extension, then print
appends the appropriate
one.
print(
specifies
additional options that are available for some formats.filename
,formattype
,formatoptions
)
print
prints the current figure to the
default printer.
print(
specifies the printer. Specify the
printer as a character vector or string containing the printer name preceded by
printer
)-P
, for example, '-Pmy printer'
. The
printer must be set up on your system.
print(
specifies
the driver. Use this option if you want to ensure that the printed
output is either black and white or color.driver
)
print(
copies
the current figure to the clipboard using the format specified by '-clipboard'
,clipboardformat
)clipboardformat
.
You can paste the copied figure into other applications.
print(
maximizes the figure
size to fill the page. Specify resize
,___)resize
as
'-bestfit'
to preserve the figure's aspect ratio or
'-fillpage'
to ignore the aspect ratio. These options are
valid only when saving to a page format (PDF, and PS) or printing to a printer.
Use this option with any of the input arguments from the previous
syntaxes.
print(
uses the specified
resolution. Specify the resolution as a character vector or string containing an
integer value preceded by resolution
,___)-r
, for example,
'-r200'
. Use this option with any of the input arguments
from the previous syntaxes.
print(
uses
the specified renderer. Specify the renderer as either
renderer
,___)'-vector'
or '-image'
.
returns the RGB image
data for the current figure. This option differs from screen captures in that
all printing features apply to the output. You can also specify the
cdata
= print('-RGBImage');resolution
, renderer
, and
fig
options with this syntax. However, you cannot
specify a Simulink block diagram.
Examples
Input Arguments
Output Arguments
Limitations
Starting MATLAB in no display mode on Linux or using the
-noFigureWindows
startup option on any platform has these limitations forprint
:Printing or saving figures with visible uicontrols errors.
Always uses the painters renderer, even if you specify the
'-image'
option.
In MATLAB Online™,
print
only prints to PDF. For additional file format options, save the figure to a file by specifying afilename
.When MATLAB is in no display mode, all Simulink printing functionality, including printing to a file, is turned off.
More About
Tips
You can set properties of the figure to control some printing and saving parameters. This table lists properties of the figure related to printing and saving.
Figure Property Description PaperPosition
Size of the printed or saved figure. If printing to a printer or a full-page output format, then this property also determines the figure location on the page. PaperPositionMode
Specifies whether to use the PaperPosition
property or the size of the figure on the screen to set the size of the printed or saved figure.InvertHardcopy
Specifies whether to use the current background color of the figure or to change the background color to white when printing or saving the figure. PaperOrientation
Figure orientation on printed page. PaperType
Standard printer paper size. PaperSize
Custom width and height of printer paper. PaperUnits
Units for the PaperSize
andPaperPosition
properties.If you are using a Linux or Mac system and get an error about an invalid or unrecognized printer, save the contents of the figure as a PDF file. For example:
Then print the PDF file using an external PDF viewer.print('MyPlot.pdf','-dpdf')
If you print a figure that has a callback defined for the
SizeChangedFcn
property and if the output size differs from the size of the figure on the screen, then theprint
function displays a warning message. To avoid the warning message, set thePaperPositionMode
property for the figure to'auto'
.
Alternative Functionality
The exportgraphics
function saves the contents of any axes, figure, chart
that can be a child of a figure, tiled chart layout, or container such as a
panel. (since R2020a)
exportgraphics
is a better alternative to the
print
function when you want to:
Save graphics displayed in an app or in MATLAB Online
Minimize the white space around the content
Save a PDF fragment with embeddable fonts
Save a multipage PDF (since R2021b)
Save a subset of the content in the figure
Control the background color without having to modify properties on the figure
The copygraphics
function provides much of the same functionality as the
exportgraphics
function, except that it copies the content to
your system clipboard instead of saving it to a file. Use this function to copy and
paste content from MATLAB into other applications. (since R2020a)
Version History
Introduced before R2006aSee Also
savefig
| saveas
| copygraphics
| exportgraphics
| getframe
| sprintf