有没有办法在 MATLAB App Designer UIAxes 中显示箱线图?

问题描述

我正在寻找一种在 UIAxes 箱线图中显示方法。我考虑将绘图保存为 .png 格式,然后使用 MATLAB 的 imshow 函数。但是我更愿意避免这个过程,因为结果不是最好的。

解决方法

UIAxes 上的箱线图(以编程方式)

通过将坐标区对象作为 uiaxes 函数调用的第一个参数传递,可以在一组 boxplot() 上绘制箱线图。在本例中,我通过调用 load carsmall 使用内置于 MATLAB 中的数据。 uiaxes (UIAxes) 的父级是 uifigure (App)。

Boxplot Plotted on UIAxes

%App figure properties%
App = uifigure();
App.Name = "GUI";
X_Position = 200; Y_Position = 200;
Height = 300; Width = 600;
App.Position = [X_Position Y_Position Width Height];

UIAxes = uiaxes(App);

%Using built-in sample data to create boxplot%
load carsmall
boxplot(UIAxes,MPG,Origin);
X_Position = 100; Y_Position = 20;
Height = 250; Width = 400;
UIAxes.Position = [X_Position Y_Position Width Height];
UIAxes.XLabel.String = 'Country of Origin';
UIAxes.YLabel.String = 'Miles per Gallon (MPG)';
UIAxes.Title.String = 'Miles per Gallon by Vehicle Origin';