主要内容

在应用程序设计师中显示图形

应用程序设计师图形概述

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 this argument. The reason is that, in most contexts, MATLAB defaults to using theGCF或者gca功能s to get the target object for an operation. But these functions depend on theHandleVisibility父人的属性为'on', 和theHandleVisibilityproperty of App Designer figures is set to'离开'默认。这意味着GCFgca不要正常工作。结果,省略目标轴或父对象的参数可能会产生意外的结果。

Depending on the graphics function you call, you might need to specify:

  • AUIAxes画布上的组件

  • A parent container in your app

  • An axes component that you create programmatically in your app code

There are a number of ways to specify the target component for a graphics function. Some examples of the most common syntaxes are given below. To determine the correct target and syntax in your context, see the documentation for the specific graphics function you are using.

在现有轴上显示图形

The most common way to display graphics in App Designer is to specify aUIAxes应用程序设计器帆布上的对象作为图形功能目标。当您从组件库onto the canvas, this creates aUIAxes您的应用中的对象。应用程序设计器轴对象的默认名称为app.UIAxes。To determine or change the name of a specific axes on your canvas, select the axes component. Its name is listed and can be edited in theComponent Browser

指定Axes as First Argument

许多图形函数具有可选的第一个输入参数来指定目标轴对象。例如,两个plot功能和thehold功能take a target axes object in this way. To plot two lines on a set of axes on the canvas, specify the name of the axes object as the first argument to each function you call.

plot(app.UIAxes,[1 2 3 4],'-r');hold(app.UIAxes); plot(app.UIAxes,[10 9 4 7],'--b');

将轴指定为名称值参数

一些图形功能要求将目标轴对象指定为名称值参数。例如,当您致电ImshowTriplot功能,指定使用该轴对象在使用该轴对象“父母”名称值参数。此代码在画布上的现有轴上显示图像:

Imshow('peppers.png',“父母”,app.UIAxes);

Display Graphics in Container

一些图形功能显示在容器组件中,例如图,面板或网格布局,而不是轴对象。例如,heatmap功能has an optional first argument for specifying the container that the chart will display in.

每个应用程序设计器应用都有一个图对象,默认为app.UIFigure,这是组成主应用程序窗口的组件的容器。指定app.UIFigure作为父容器参数以在主应用程序窗口中显示图形。例如,要在应用程序中创建热图,请使用此语法:

h = heatmap(app.uifigure,rand(10));

为了进一步组织和划分摄入父容器输入参数的图形,请将容器组件(例如面板,选项卡或网格布局)拖动组件库onto the canvas. Determine the name of the component by selecting it and viewing its name in theComponent Browser。You can then specify this container as the parent when you call the graphics function.

其他常用的图​​形功能,将父容器作为输入包含annotation,geobubble,parallelplot,分散组织图,stackedplot, 和wordcloud

编程创建轴

一些图形功能在专用轴上绘制数据。例如,绘制极性数据的函数必须在PolarAxes目的。与众不同UIAxesobjects, which you can add to your app from the组件库,您必须在应用程序中添加专门轴以编程方式在您的代码中。要以编程方式创建轴对象,请创建一个StartupFcn您的应用程序回调。在其中,调用适当的图形功能,并将应用程序中的父容器指定为目标。

Plot on Polar Axes

功能,例如polarplot,极性组织图, 和polarscattertake a polar axes object as a target. Create a polar axes programmatically by calling thepolaraxes功能。For example, to plot a polar equation in a panel, first drag a panel component from the组件库在你的画布上。在您的应用程序的代码中,通过调用polaraxes功能和specifying the panel as the parent container. Then, plot your equation with thepolarplot功能, specifying the polar axes as the target axes.

theta = 0:0.01:2*pi;rho = sin(2*theta)。*cos(2*theta);pax = polaraxes(app.panel);PolarPlot(Pax,Theta,Rho)

地理轴

功能,例如geoplot,地理学家, 和geodensityplottake a geographic axes object as a target. Create a geographic axes programmatically by calling thegeoaxes功能。For example, to plot geographic data in a panel, use the following code:

latSeattle = 47 + 37/60; lonSeattle = -(122 + 20/60); gx = geoaxes(app.Panel); geoplot(gx,latSeattle,lonSeattle)

Create Tiled Chart Layout

使用多个图表使用tiledlayout功能,在面板中创建一个瓷砖图表,然后使用该轴来编程创建轴nexttile功能。从轴对象返回nexttile功能并使用它来指定图表或图的轴。

t = tiledlayout(app.Panel,2,1); [X,Y,Z] = peaks(20)% Tile 1ax1 = nexttile(t);冲浪(AX1,X,Y,Z)% Tile 2ax2 = nexttile(t); contour(ax2,X,Y,Z)

Use Functions with No Target Argument

一些图形功能,例如ginputgtext,没有指定目标的论点。结果,您必须设置HandleVisibilityproperty of the App Designer figure to'callback'或者'on'在调用这些功能之前。调用这些功能后,您可以设置HandleVisibility财产回到'离开'。例如,此代码显示如何定义回调,该回调允许您使用该回调来识别两个点的坐标ginput功能。

功能pushButtonCallback(app,event) app.UIFigure.HandleVisibility ='callback'; ginput(2) app.UIFigure.HandleVisibility ='离开';end

使用不支持自动调整大小的功能万博1manbetx

默认应用程序设计师数据是可调整大小的。这意味着when you run an app and resize the figure window, components in the figure are automatically resized and repositioned to fit. However, some graphics functions do not support automatic resizing. To use these functions in App Designer, create a panel in which to display the output of the function and set theAutoresizechildrenproperty of the panel to'离开'。您可以在控制板tab of theComponent Browser或在您的代码中。

例如,子图功能does not support automatic resizing. To use this function in your app:

  1. 将面板组件从组件库在你的画布上。

  2. Set theAutoresizechildrenproperty of the panel to'离开'

  3. 指定the panel as the parent container using the“父母”呼叫时的名称值参数子图。Also, specify an output argument to store the axes.

  4. 用轴调用绘图函数为第一个输入参数。

app.Panel.AutoResizeChildren ='离开'; ax1 = subplot(1,2,1,“父母”,app.panel);AX2 =子图(1,2,2,“父母”,app.panel);图(AX1,[1 2 3 4])图(AX2,[10 9 4 7])

其他不支持自动调整大小的常用功能包括万博1manbetxparetoplotmatrix

有关管理调整大小行为的更多信息,请参阅Alternatives to Default Auto-Resize Behaviors

Unsupported Functionality

从R2022A开始,应用程序设计器不支持一些图形功能。万博1manbetx该表列出了与应用程序构建工作流程最相关的不支持万博1manbetx功能。

类别 Not Supported
Retrieving and Saving Data

这些功能不支持:万博1manbetxhgexport,HGLOAD,HGSAVE,节省,load,节省fig,OpenFig, 和另存为, 和print

Instead of the另存为或者print功能s, use theexportapp功能to save the content of an app window. To save plots in an app, use theexportgraphics或者copygraphics功能。

通过编程创建的数字uifigure支持万博1manbetx节省,load,节省fig, 和OpenFig功能。

Web Apps

If you are using App Designer to create a deployed web app (requiresMATLAB编译器™),适用其他图形限制。

有关更多信息,请参阅Web应用程序限制和不支持的功能万博1manbetx(MATLAB Compiler)

See Also

|

Related Topics