Displaying graphics in App Designer requires a different workflow than you typically use at the MATLAB® command line. Once you understand this workflow and a few special cases, you will know how to call the functions you need for displaying almost any type of plot.
Many of the graphics functions in MATLAB (and MATLAB toolboxes) have an argument for specifying the target axes or parent
object. This argument is optional in most contexts, but when you call these functions in
App Designer, you must specify that argument. Otherwise, MATLAB uses
gca to get the target object for the operation. However,
gcf cannot return an App Designer figure, and
gca cannot return any axes within an App Designer figure. Thus,
omitting the argument might produce unexpected results.
plot(app.UIAxes,[1 2 3 4],'-r'); hold(app.UIAxes); plot(app.UIAxes,[10 9 4 7],'--b');
You can create most 2-D and 3-D plots using the App Designer axes (a
uiaxes object). Starting in R2018b, you can create additional plots,
such as those listed in the following table. Most of these plots require a different
type of parent object and additional lines of code in your app. All of them use
normalized units by default.
Create the polar axes by calling the
theta = 0:0.01:2*pi; rho = sin(2*theta).*cos(2*theta); pax = polaraxes(app.UIFigure); polarplot(pax,theta,rho)
Follow these steps:
app.UIFigure.AutoResizeChildren = 'off'; ax1 = subplot(1,2,1,'Parent',app.UIFigure); ax2 = subplot(1,2,2,'Parent',app.UIFigure); plot(ax1,[1 2 3 4]) plot(ax2,[10 9 4 7])
Follow these steps:
app.UIFigure.AutoResizeChildren = 'off'; ax = axes(app.UIFigure); pareto(ax,[10 20 40 40])
Specify the parent container when calling these functions
h = heatmap(app.UIFigure,rand(10));
Create the geographic axes by calling the
latSeattle = 47 + 37/60; lonSeattle = -(122 + 20/60); gx = geoaxes(app.UIFigure); geoplot(gx,latSeattle,lonSeattle)
As of R2019a, some graphics functionality is not supported in App Designer. This table lists the functionality that is relevant to most app building workflows.
|Retrieving and Saving Data|
Figures created programmatically with
|Functions not Recommended|
|Axes in Grid Layout Managers or Scrollable Containers|