uiaxes
Create UI axes for plots in apps
Description
creates a UI axes in a new
figure window and returns the ax
= uiaxesUIAxes
object.
MATLAB® calls the uifigure
function to create the
figure.
UIAxes
objects are useful for creating Cartesian plots in apps.
They are very similar to the Cartesian Axes
objects returned by
the axes
function. Thus, you can pass a
UIAxes
object to most functions that accept an
Axes
object. For more information, see Differences Between UIAxes and Axes Objects.
specifies ax
= uiaxes(Name,Value
)UIAxes
property values using one or more
Name,Value
pair arguments.
specifies ax
= uiaxes(parent
,Name,Value
)UIAxes
property values using one or more
Name,Value
arguments.
Examples
Create Plots in UI Axes
Create a line plot and a scatter plot in UI axes.
Create a figure window with UI axes and assign the UIAxes
object to the variable ax
. Add a
line plot to the axes by specifying the UIAxes
object as the first input argument for the
plot
function.
fig = uifigure; ax = uiaxes(fig); x = linspace(-pi,pi,50); y = 5*sin(x); plot(ax,x,y)
Set the hold state on and add a scatter plot. Specify the UIAxes
object as the first input argument for
the hold
and scatter
functions.
hold(ax,'on')
y2 = 5*sin(x) + randn(1,50);
scatter(ax,x,y2)
Specify UI Axes Properties
Modify the appearance of the UI axes by setting properties
using name-value pair arguments. For example, reverse the
x-axis direction using the XDir
name-value pair.
fig = uifigure; ax = uiaxes(fig,'XDir','reverse'); x = linspace(-pi,pi); y = sin(x); plot(ax,x,y)
Alternatively, specify properties after the axes is created using dot
notation. For example, reverse the y-axis direction
using dot notation to access the YDir
property.
ax.YDir = 'reverse';
Specify UI Axes Position
Specify the UI axes position by setting the
Position
property. Specify the position in pixels.
fig = uifigure;
ax = uiaxes(fig,'Position',[10 10 550 400]);
Add UI Axes to Panel
Add UI axes to a panel within a figure window. Specify the panel and axes positions in pixels.
fig = uifigure; p = uipanel(fig,'Position',[10 10 400 400]); ax = uiaxes(p,'Position',[10 10 370 370]);
Input Arguments
parent
— Parent container
Figure
object | Panel
object | Tab
object | GridLayout
object | TiledChartLayout
object
Parent container, specified as a Figure
,
Panel
, Tab
, GridLayout
, or TiledChartLayout
object. If
no container is specified, MATLAB calls the uifigure
function to create a
new Figure
object that serves as the
parent container.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'Xscale','linear','YScale','log'
The properties list here are only a subset. For a full list, see UIAxes Properties.
XLim
, YLim
, ZLim
— Minimum and maximum axis limits
[0 1]
(default) | two-element vector of the form [min max]
Minimum and maximum limits, specified as a two-element vector of the form
[min max]
, where max
is greater than
min
. You can specify the limits as numeric, categorical,
datetime, or duration values. However, the type of values that you specify must match
the type of values along the axis.
You can specify both limits, or specify one limit and let MATLAB automatically calculate the other. For an automatically calculated minimum
or maximum limit, use -inf
or inf
, respectively.
MATLAB uses the 'tight'
limit method to calculate the
corresponding limit.
Example: ax.XLim = [0 10]
Example: ax.YLim = [-inf 10]
Example: ax.ZLim = [0 inf]
Alternatively, use the xlim
, ylim
, and zlim
functions to set the limits. For an
example, see Specify Axis Limits.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| datetime
| duration
XScale
, YScale
, ZScale
— Scale of values along axis
'linear'
(default) | 'log'
Axis scale, specified as one of these values.
Value | Description | Result |
---|---|---|
'linear' | Linear scale Example:
| |
'log' | Log scale Example:
Note The axes might exclude coordinates in some cases:
|
GridLineStyle
— Line style for grid lines
'-'
(default) | '--'
| ':'
| '-.'
| 'none'
Line style for grid lines, specified as one of the line styles in this table.
Line Style | Description | Resulting Line |
---|---|---|
"-" | Solid line |
|
"--" | Dashed line |
|
":" | Dotted line |
|
"-." | Dash-dotted line |
|
"none" | No line | No line |
To display the grid lines, use the grid on
command or
set the XGrid
, YGrid
, or
ZGrid
property to 'on'
.
Example: ax.GridLineStyle = '--'
Position
— Size and location of axes, including labels and margins
[10 10 400 300]
(default) | four-element vector
Size and location of axes, including the labels and margins, specified as a four-element
vector of the form [left bottom width height]
. This property is
equivalent to the OuterPosition
property. The vector defines a
rectangle that encloses the outer bounds of the axes. The values are measured in the
units specified by the Units
property, which defaults to pixels.
The
left
andbottom
elements define the position of the rectangle, measured from the lower left corner of the parent container.The
width
andheight
define the size of the rectangle.
If you want to specify the position and account for the text around the axes, then set
the either the Position
or the OuterPosition
property. These figures show the areas defined by the Position
(or
OuterPosition
) in blue, and the
InnerPosition
in red.
2-D View of Axes | 3-D View of Axes |
---|---|
|
|
Note
Setting this property has no effect when the parent container is a
TiledChartLayout
object.
Output Arguments
ax
— UIAxes
object
UIAxes
object
UIAxes
object. Use ax
to set properties of the UIAxes
after they
are created.
More About
Differences Between UIAxes
and Axes
Objects
This table describes the properties that are different for
UIAxes
and Axes
objects. For more
information on creating charts in apps, see Display Graphics in App Designer.
Property | UIAxes Objects | Axes Objects |
---|---|---|
NextPlot | The default value is
Note
that passing a | The default value is
|
Position | The default The
| The default The
|
Units | The default value is
| The default value is
|
FontUnits | The default value is
| The default value is
|
Version History
Introduced in R2016a
See Also
Functions
Properties
Tools
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
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: .
You can also select a web site from the following 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érica Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (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
- United Kingdom (English)