This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 an ActivePositionProperty property set to 'outerposition'. By default, it does not affect subplots since subplots have an ActivePositionProperty set to 'position'.

Click Apply to Figure. Applying the settings changes the appearance of the figure on the screen. All settings from the Export Setup dialog 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 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.

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.

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.

Save Figure Settings for Future Use

Save your settings to use for future figures by creating an export style. In the Export Styles section, type a style name, for example MyCustomSettings. Then, click Save.

Apply Settings to Another Figure

Apply your settings to another figure by opening the Export Setup box from its figure menu. In the Export Styles section, select the style name and click Load. Next, click Apply to Figure on the right side of the Export Setup dialog. MATLAB applies the saved style settings to the figure.

Restore Figure to Original Settings

Restore the figure on the screen to the original settings by clicking Restore Figure.

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