Print figure or save to specific file format
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
,___)'-painters'
or '-opengl'
.
print(
excludes
user interface controls, such as push buttons and sliders, from the
saved or printed output. It does not exclude user interface objects
that can contain an axes, such as a uitab or uipanel.'-noui'
,___)
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
, '-noui'
,
and fig
options with this syntax. However, you
cannot specify a Simulink block diagram.
Starting MATLAB in no display mode on Linux or
using the -noFigureWindows
startup option on any
platform has these limitations for print
:
Printing or saving figures with visible uicontrols
errors. To print or save the figure, hide the uicontrols by setting
their Visible
properties to 'off'
,
or use the '-noui'
option with the print
function.
Always uses the painters renderer, even if you specify
the '-opengl'
option.
In MATLAB
Online™, print
only prints to PDF. For additional
file format options, save the figure to a file by specifying a filename
.
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 and PaperPosition properties. |
If you are using a Linux or Mac system and get an error about an invalid or unrecognized printer,
then try specifying a PostScript driver for the driver
option. If the printer
supports PostScript level 3, try '-dps'
for black and white or
'-dpsc'
for color. If the printer supports PostScript level 2, then try '-dps2'
for black and white
or '-dps2c'
for color. For
example:
print('-dpsc','-Pmy printer')
printopt
file. Alternatively, print the figure to a PDF file. Then, print the PDF from an
external PDF viewer.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 the print
function
displays a warning message. To avoid the warning message, set the PaperPositionMode
property
for the figure to 'auto'
.
Starting in R2020a, you can use the exportgraphics
function to save the contents of any axes, figure, chart
that can be a child of a figure, tiled chart layout, or container such as a panel. This
function provides 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 subset of the content in the figure
Control the background color without having to modify properties on the figure
The copygraphics
function (also new in R2020a) 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.
copygraphics
| exportgraphics
| getframe
| saveas
| savefig
| sprintf