Main Content

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'.

Export Setup window displaying the Size Properties panel. The Width field is set to 5 and the Height field is set to 4.

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.

Figure containing a line plot against a white background

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.

Rendering Properties panel with the Custom color field set 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 NameShort NameCorresponding RGB Triplet
whitew[1 1 1]
yellowy[1 1 0]
magentam[1 0 1]
redr[1 0 0]
cyanc[0 1 1]
greeng[0 1 0]
blueb[0 0 1]
blackk[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.

Fonts Properties panel with the Use fixed font size field set to 20, the Custom name field set to Helvetica, the Custom weight field set to bold, and the Custom angle field set to normal

Change the line width by clicking the Lines property. Specify a fixed line width, for example, 2 points.

Lines Properties panel with the Use fixed line width field set to 2

Click Apply to Figure on the right side of the Export Setup dialog box.

Figure with a yellow background containing a line plot that has a 2-point line and 20-point bold tick labels

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.

Export button in the Export Setup window

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

| |

Related Topics