Customize Figure Before Saving
This example shows how to use the Export Setup window to customize a figure before saving it. It shows how to change the figure size, background color, font size, and line width. It also shows how to save the settings as an export style that you can apply to other figures before saving them.
Set Figure Size
Create a line plot.
x = linspace(0,10); y = sin(x); plot(x,y)
Set the figure size by clicking File > Export Setup. Specify the desired dimensions in the Width and Height fields, for example 5-by-4 inches. The dimensions include the entire figure window except for the frame, title bar, menu bar, and any tool bars. If the specified width and height are too large, then the figure might not reach the specified size.
To make the axes fill the figure, select Expand axes to fill
figure. This option only affects axes with a
PositionConstraint
property set to
'outerposition'
.
Click Apply to Figure. Applying the settings changes the appearance of the figure on the screen. All settings from the Export Setup dialog box are applied to the figure. Thus, more than just the figure size can change. For example, by default, MATLAB® converts the background color of the saved figure to white.
Set Figure Background Color
Set the figure background color by clicking the Rendering property in the Export Setup window. In the Custom color field, specify either a color name from the table or an RGB triplet. For example, set the background color to yellow.
An RGB triplet is a three-element row vector whose elements specify the intensities of the
red, green, and blue components of the color. The intensities must be in the range
[0,1]
, for example, [0.4 0.6 0.7]
. This table lists some
common RGB triplets that have corresponding color names. To specify the default gray background
color, set the Custom color field to default
.
Long Name | Short Name | Corresponding RGB Triplet |
---|---|---|
white | w | [1 1 1] |
yellow | y | [1 1 0] |
magenta | m | [1 0 1] |
red | r | [1 0 0] |
cyan | c | [0 1 1] |
green | g | [0 1 0] |
blue | b | [0 0 1] |
black | k | [0 0 0] |
Set Figure Font Size and Line Width
Change the font by clicking the Fonts property. Specify a fixed font size and select a font name, font weight, and font angle. For example, use 20 point bold font. The tick mark locations might change to accommodate the new font size.
Change the line width by clicking the Lines property. Specify a
fixed line width, for example, 2
points.
Click Apply to Figure on the right side of the Export Setup dialog box.
Save Figure to File
Save the figure to a file by first clicking Export, and then
specifying a file name, location, and desired format. For more information about file formats,
see saveas
.
Customize Figure Programmatically
Alternatively, you can customize your figure programmatically. To customize the
figure programmatically, set properties of the graphics objects. Typically, graphics
functions return output arguments that you can use to access and modify graphics
objects. For example, assign the chart line objects returned from the
plot
function to a variable and set their
LineWidth
property.
p = plot(rand(5));
set(p,'LineWidth',3)
If you do not return the graphics objects as output arguments, you can use
findobj
to find objects with certain
properties. For example, find all objects in the current figure with a
Type
property set to 'line'
. Then, set
their LineWidth
property.
plot(rand(5)) p = findobj(gcf,'Type','line') set(p,'LineWidth',3);
For a list of all graphics objects and their properties, see Graphics Object Properties.
See Also
saveas
| print
| Property Inspector