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 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(
specifies the type of content to create as contenttype
,___)"-vector"
(for
vector graphics) or "-image"
(for images).
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
, contenttype
, and
fig
options with this syntax. However, you cannot
specify a Simulink block diagram.
Examples
Input Arguments
Output Arguments
Limitations
In MATLAB Online™,
print
prints to a PDF instead of printing to a printer. However, you can save the figure as another type of 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.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")
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.
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.
Version History
Introduced before R2006aSee Also
savefig
| saveas
| copygraphics
| exportgraphics
| getframe
| sprintf