主要内容

figure

Create figure window

Description

figurecreates a new figure window using default property values. The resulting figure is thecurrent figure

example

figure(Name,Value)modifies properties of the figure using one or more name-value pair arguments. For example,figure('Color','white')sets the background color to white.

example

f= figure(___)returns theFigure目的。利用fto query or modify properties of the figure after it is created.

example

figure(f)makes the figure specified byfthe current figure and displays it on top of all other figures.

figure(n)finds a figure in which theNumberproperty is equal ton, and makes it the current figure. If no figure exists with that property value, MATLAB®creates a new figure and sets itsNumberproperty ton

Examples

collapse all

Create a default figure.

f = figure;

Figure window

获取图的位置,宽度和高度。

f.Position
ans = 680 558 560 420

This means that the figure window is positioned 680 pixels to the right and 558 pixels above the bottom left corner of the primary display, and is 560 pixels wide and 420 pixels tall.

Halve the figure width and height by adjusting the third and fourth elements of the position vector.

f.Position(3:4) = [280 210];

Figure window with width and height halved

Create a figure, and specify theNameproperty. By default, the resulting title includes the figure number.

figure('Name','Measured Data');

Figure window with title

Specify theNameproperty again, but this time, set theNumberTitleproperty to'离开'。结果标题不包括图编号。

figure('Name','Measured Data','NumberTitle','离开');

Figure window with title

Create two figures, and then create a line plot. By default, theplotcommand targets the current figure.

f1 = figure; f2 = figure; plot([1 2 3],[2 4 6]);

两个带标题“图1”和“图2”的图形窗口。图2位于前景中,并包含带有一些数据的图。

Set the current figure tof1,使其成为下一个图的目标。然后创建一个散点图。

figure(f1); scatter((1:20),rand(1,20));

Two figure windows. Figure 1 is in the foreground and contains a scatter plot with some data.

Input Arguments

collapse all

Target figure, specified as aFigure目的。

目标图编号,指定为标量整数值。当您指定此参数时,MATLAB搜索了现有的图形Numberproperty is equal ton。如果没有该属性值的数字,MATLAB将创建一个新图形并设置其Numberproperty ton。By default, theNumber属性值显示在图的标题中。

Data Types:double

Name-Value Arguments

例子:figure('Color','white')creates a figure with a white background.

Specify optional comma-separated pairs ofName,Value参数。Nameis the argument name andValueis the corresponding value.Namemust appear inside single quotes (' '). You can specify several name and value pair arguments asNAME1,Value1,...,Namen,Valuen

Note

这properties listed here are only a subset. For a full list, see图属性

Name of the figure, specified as a character vector or a string scalar.

例子:figure('Name','Results')将图的名称设置为'Results'

By default, the name is'Figuren', wherenis an integer. When you specify theNameproperty, the title of the figure becomes'Figuren:name'。If you want only theName出现的价值,设置IntegerHandleorNumberTitleto'离开'

Background color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. If you specify'none',背景颜色在屏幕上显示为黑色,但是如果您打印图形,则背景会像图形窗口透明一样打印。

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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]

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#),然后是三个或六个十六进制的数字,范围从0toF。这values are not case sensitive. Thus, the color codes'#FF8800','#ff8800','#F80', and'#f80'are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color Name 简称 RGB Triplet Hexadecimal Color Code Appearance
“红色” 'r' [1 0 0] '#FF0000'

颜色红色样品

'green' 'g' [0 1 0] '#00FF00'

颜色绿色样品

'蓝色的' 'b' [0 0 1] '#0000FF'

Sample of the color blue

'cyan' 'c' [0 1 1] '#00FFFF'

Sample of the color cyan

'品红' 'M' [1 0 1] '#FF00FF'

Sample of the color magenta

'yellow' 'y' [1 1 0] '#FFFF00'

Sample of the color yellow

'black' 'K' [0 0 0] '#000000'

Sample of the color black

'white' 'w' [1 1 1] '#FFFFFF'

Sample of the color white

'none' Not applicable Not applicable Not applicable No color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB Triplet Hexadecimal Color Code Appearance
[0 0.4470 0.7410] '#0072BD'

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980] '#D95319'

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250] '#EDB120'

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560] '#7E2F8E'

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880] '#77AC30'

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330] '#4dbeee'

RGB三胞胎样品[0.3010 0.7450 0.9330],如浅蓝色

[0.6350 0.0780 0.1840] '#A2142F'

RGB三重态样品[0.6350 0.0780 0.1840],看起来为深红色

Data Types:double|char

Location and size of the drawable area, specified as a vector of the form[left bottom width height]。该区域不包括人物边界,标题栏,菜单栏和工具栏。

This table describes each element in thePosition向量。

Element Description
left Distance from the left edge of the primary display to the inner left edge of the window. This value can be negative on systems that have more than one monitor.

If the figure is docked, then this value is relative to the Figure panel within the MATLAB desktop.
底部 Distance from the bottom edge of the primary display to the inner bottom edge of the window. This value can be negative on systems that have more than one monitor.

If the figure is docked, then this value is relative to the Figure panel within the MATLAB desktop.
宽度 Distance between the right and left inner edges of the figure.
height Distance between the top and bottom inner edges of the window.

All measurements are in units specified by the单位property.

You cannot specify the figurePositionproperty when the figure is docked.

InMATLAB Online™,底部andleftelements of thePositionvector are ignored.

To place the full window, including the borders, title bar, menu bar, tool bars, use theOuterPositionproperty.

Note

这Windows®operating system enforces a minimum window width and a maximum window size. If you specify a figure size outside of those limits, the displayed figure will conform to the limits instead of the size you specified.

单位of measurement, specified as one of the values from this table.

单位Value Description
'pixels'(default)

Pixels.

Starting in R2015b, distances in pixels are independent of your system resolution on Windows andMacintoshsystems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • OnMacintosh系统,像素是1/72的1英寸。

On Linux®systems, the size of a pixel is determined by your system resolution.

'normalized' 这se units are normalized with respect to the parent container. The lower-left corner of the container maps to(0,0)and the upper-right corner maps to(1,1)
'inches' Inches.
'centimeters' Centimeters.
'points' Points. One point equals 1/72nd of an inch.
'characters'

这se units are based on the default uicontrol font of the graphics root object:

  • Character width = width of the letterx

  • Character height = distance between the baselines of two lines of text.

To access the default uicontrol font, useget(groot,'defaultuicontrolFontName')orset(groot,'defaultuicontrolFontName')

MATLAB measures all units from the lower left corner of the parent object.

This property affects thePositionproperty. If you change the单位property, consider returning its value to the default value after completing your computation to avoid affecting other functions that assume the default value.

这order in which you specify the单位andPosition属性具有这些影响:

  • If you specify the单位before thePositionproperty, then MATLAB setsPositionusing the units you specify.

  • If you specify the单位property after thePositionproperty, MATLAB sets the position using the default单位。然后,MATLAB转换Position在您指定的单位中的等效值值。

More About

collapse all

当前图

这current figure is the target for graphics commands such asaxesandcolormap。通常,这是创建的最后一个数字或鼠标单击的最后一个数字。这gcfcommand returns the current figure.

提示

  • 使用图形根对象在其他类型的对象的根级别上设置默认值。例如,将所有未来数字的默认colormap设置为summercolormap.

    set(groot,'DefaultFigureColormap',夏天)
    To restore a property to its original MATLAB default, use the'remove'keyword.
    set(groot,'DefaultFigureColormap','remove')
    For more information on setting default values, seeDefault Property Values

Version History

Introduced before R2006a

See Also

Functions

Properties