figure
Create figure window
Description
figure
creates a new figure window using default property values. The resulting figure is thecurrent figure。
figure(
modifies properties of the figure using one or more name-value pair arguments. For example,Name,Value
)figure('Color','white')
sets the background color to white.
figure(
makes the figure specified byf
)f
the current figure and displays it on top of all other figures.
figure(
finds a figure in which then
)Number
property is equal ton
, and makes it the current figure. If no figure exists with that property value, MATLAB®creates a new figure and sets itsNumber
property ton
。
Examples
Change Figure Size
Create a default figure.
f = figure;
获取图的位置,宽度和高度。
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];
指定图标题
Create a figure, and specify theName
property. By default, the resulting title includes the figure number.
figure('Name','Measured Data');
Specify theName
property again, but this time, set theNumberTitle
property to'离开'
。结果标题不包括图编号。
figure('Name','Measured Data','NumberTitle','离开');
Working with Multiple Figures Simultaneously
Create two figures, and then create a line plot. By default, theplot
command targets the current figure.
f1 = figure; f2 = figure; plot([1 2 3],[2 4 6]);
Set the current figure tof1
,使其成为下一个图的目标。然后创建一个散点图。
figure(f1); scatter((1:20),rand(1,20));
Input Arguments
f
—Target figure
Figure
object
Target figure, specified as aFigure
目的。
n
—Target figure number
scalar integer value
目标图编号,指定为标量整数值。当您指定此参数时,MATLAB搜索了现有的图形Numberproperty is equal ton
。如果没有该属性值的数字,MATLAB将创建一个新图形并设置其Number
property 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
参数。Name
is the argument name andValue
is the corresponding value.Name
must 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
—Name
''
(default) |character vector|string scalar
Name of the figure, specified as a character vector or a string scalar.
例子:figure('Name','Results')
将图的名称设置为'Results'
。
By default, the name is'Figuren'
, wheren
is an integer. When you specify theName
property, the title of the figure becomes'Figuren:name'
。If you want only theName
出现的价值,设置IntegerHandle
orNumberTitle
to'离开'
。
Color
—Background color
RGB triplet|hexadecimal color code|'r'
|'g'
|'b'
| ...
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 (
#
),然后是三个或六个十六进制的数字,范围从0
toF
。这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' |
|
'cyan' |
'c' |
[0 1 1] |
'#00FFFF' |
|
'品红' |
'M' |
[1 0 1] |
'#FF00FF' |
|
'yellow' |
'y' |
[1 1 0] |
'#FFFF00' |
|
'black' |
'K' |
[0 0 0] |
'#000000' |
|
'white' |
'w' |
[1 1 1] |
'#FFFFFF' |
|
'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' |
|
[0.8500 0.3250 0.0980] |
'#D95319' |
|
[0.9290 0.6940 0.1250] |
'#EDB120' |
|
[0.4940 0.1840 0.5560] |
'#7E2F8E' |
|
[0.4660 0.6740 0.1880] |
'#77AC30' |
|
[0.3010 0.7450 0.9330] |
'#4dbeee' |
|
[0.6350 0.0780 0.1840] |
'#A2142F' |
|
Data Types:double
|char
Position
—Location and size of drawable area
[left bottom width height]
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 figurePosition
property when the figure is docked.
InMATLAB Online™,底部
andleft
elements of thePosition
vector are ignored.
To place the full window, including the borders, title bar, menu bar, tool bars, use theOuterPosition
property.
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
'pixels'
(default) |'normalized'
|'inches'
|'centimeters'
|'points'
|'characters'
单位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 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:
To access the default uicontrol font, use |
MATLAB measures all units from the lower left corner of the parent object.
This property affects thePosition
property. 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 thePosition
property, then MATLAB setsPosition
using the units you specify.If you specify the
单位
property after thePosition
property, MATLAB sets the position using the default单位
。然后,MATLAB转换Position
在您指定的单位中的等效值值。
More About
当前图
这current figure is the target for graphics commands such asaxes
andcolormap
。通常,这是创建的最后一个数字或鼠标单击的最后一个数字。这gcf
command returns the current figure.
提示
使用图形根对象在其他类型的对象的根级别上设置默认值。例如,将所有未来数字的默认colormap设置为
summer
colormap.set(groot,'DefaultFigureColormap',夏天)
'remove'
keyword.set(groot,'DefaultFigureColormap','remove')
Version History
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
你也可以从下面选择一个网站list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- 英国(English)