Graphics Support in App Designer
The types of charts your app can support depend largely on the kind of figure that underlies the UI. Apps you create using GUIDE, and apps you create programmatically using theuicontrol
function, use traditional figures and axes. These apps support all the graphics functionality available in MATLAB®.
Apps you create using App Designer are based on a new kind of figure, called aUI figure. To display graphics in these apps, you must use a new type of axes, calledUI axes.
UI figures and UI axes are similar to traditional figures and axes, but there are some important differences to be aware of when deciding how to build your app.
Graphics Support
If you are creating an app in App Designer that displays graphics, you must specify the target UI figure or UI axes when you call certain graphics functions. Otherwise, MATLAB assumesgcf
orgca
is the target. However,gcf
andgca
cannot return UI figures and UI axes, so omitting them might lead to unexpected results.
Furthermore, UI figures do not support most of the interactive functionality that traditional figures support. For example, UI figures do not support printing, nor do they support mouse or keyboard interactions.
The following table lists the graphics functions that UI figures and UI axes support.
Category | Supported in R2016a and later | Added in R2016b | Added in R2017a | Notes |
---|---|---|---|---|
Charting Functions and Graphics Objects | alpha colormap hold line plot scatter text title |
alphamap animatedline area bar barh caxis colorbar contour contourf errorbar feather fcontour fimplicit fplot histogram image imagesc imshow legend loglog quiver rectangle semilogx semilogy stairs stem yyaxis |
comet plot (graph) triplot voronoi |
You must specify the target UI figure or UI axes when you call these functions. This code shows how to specify the target UI axes in App Designer: plot(app.UIAxes,[1 2 3 4],'-r'); hold(app.UIAxes); plot(app.UIAxes,[10 9 4 7],'--b'); Some functions (such as imshow('peppers.png','Parent',app.UIAxes); |
Coordinate Systems | box grid xlim ylim xlabel ylabel |
datetick xticks yticks xtickangle ytickangle xtickformat ytickformat xticklabels yticklabels |
Specify the UI axes as the target when using these functions. For example, this code shows how to set thex-label on a plot in App Designer: xlabel(app.UIAxes,'Frequency'); |
|
Utilities | ancestor cla delete get set findobj ishandle isgraphics newplot reset |
pbaspect (2-D) |
alim drawnow pan zoom |
You might need to specify the target UI figure or the UI axes when calling some these functions. This code shows how to find a ax = findobj(app.UIFigure,'XLim',[0 1]); This code shows how to use the pan(app.UIAxes,'on'); zoom(app.UIAxes,'on'); pan only supports the'on' and'off' arguments.zoom only supports the'on' ,'off' , andfactor arguments. |
Figures | close |
Specify the UI figure as the target. For example: f = uifigure; close(f); |
Properties and Component Support
如果你移动代码前relea写道ses into App Designer, you might encounter these limitations:
UI figures support only a subset of the properties that traditional figures support. For example, UI figures do not support properties for printing, saving, callback execution, or custom mouse and keyboard interaction. For a full list of supported properties, seeUI Figure Properties.
UI axes support only a subset of the properties that traditional axes support. For example, UI axes do not support lighting and camera properties or properties for interactive control. For a full list of supported properties, seeUIAxes Properties.
UI figures support a different set of interactive components than traditional figures do. For example, UI figures do not support components created with the
uicontrol
oruimenu
functions. For a full list of supported components, seeComponents in App Designer.Some components support only a subset of properties when you place them in UI figures. For example,
Table
UI components do not support theExtent
property in UI figures. For a list of supported properties for a particular component, see the component's property page on theComponents in App Designerpage.
See Also
UI Figure Properties|UIAxes Properties