Create UI axes for plots in apps (2024)

Create UI axes for plots in apps

collapse all in page

Syntax

ax = uiaxes

ax = uiaxes(Name,Value)

ax = uiaxes(parent)

ax = uiaxes(parent,Name,Value)

Description

example

ax = uiaxes creates a UI axes in a new figure window and returns the UIAxes 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.

example

ax = uiaxes(Name,Value) specifies UIAxes property values using one or more Name,Value pair arguments.

example

ax = uiaxes(parent) creates the UI axes in the specified parent container. The parent can be a Figure created using the uifigure function, or one of its child containers.

ax = uiaxes(parent,Name,Value) specifies UIAxes property values using one or more Name,Value arguments.

Examples

collapse all

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)

Create UI axes for plots in apps (1)

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)

Create UI axes for plots in apps (2)

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)

Create UI axes for plots in apps (3)

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]);

Create UI axes for plots in apps (4)

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 390 390]);

Create UI axes for plots in apps (5)

Input Arguments

collapse all

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

Output Arguments

collapse all

axUIAxes object
UIAxes object

UIAxes object. Use ax to set properties of the UIAxes after they are created.

More About

collapse all

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.

PropertyUIAxes ObjectsAxes Objects
NextPlot

The default value is 'replacechildren'.

Note that passing a UIAxes object to the cla function with the 'reset' option sets the NextPlot property to 'replace' unless you define a different default for the NextPlot property.

The default value is 'replace'.

Position

The default Position is [10 10 400 300] in pixels.

The Position property is equivalent to the OuterPosition property.

The default Position is [0.1300 0.1100 0.7750 0.8150] in normalized units.

The Position property is equivalent to the InnerPosition property.

Units

The default value is 'pixels'.

The default value is 'normalized'.

FontUnits

The default value is 'pixels'.

The default value is 'points'.

Version History

Introduced in R2016a

See Also

Functions

  • uifigure

Properties

  • UIAxes Properties

Tools

  • App Designer

Topics

  • Display Graphics in App Designer

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.

Create UI axes for plots in apps (6)

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:

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
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Create UI axes for plots in apps (2024)
Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5553

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.