How to create GUI plot using the UIAxes, PlotType, and RunList box

12 views (last 30 days)
Hi,
I have trouble understanding the GUI plot. I was able to get a figure pop out (as shown in Figure) on button click, but I am not able to build a GUI chart within the app, which would connect to run a whole scenario or be activated by an additional click on the button (as shown in attached GUI plot). I was not able to figure out how to assign my result for axses in the GUI. I copied the function code from GUI code view and the Figure pop out. Could you please advise how create figure that will show up in the GUI plot (as shown in the example GUI plot)?
Thank you for your help.
Kind regards,
Jasmina
function plotSpearman(app, runNum, topN) %Generate plot of top N Spearman rankings for given run number
numResults = length(app.Building.RunHistory);
names = cellstr(app.Building.RunHistory(runNum).SpearmanTable{1:topN,'Name'}); %Names of parameter (not necessarily attribute name, esp for U-vals and other SpearmanExtras)
names = regexprep(names,'_','\\_');%Prevent converting text wtih underscores to subscripts
vals = app.Building.RunHistory(runNum).SpearmanTable{1:topN,'Norm_squared_rho'}; %Normalized squared Spearman rho
% vals = app.Building.RunHistory(runNum).SpearmanTable{1:topN,'P_value'}; % P_value
fig = figure;
barh(vals);
title('Attribute ranking');
xtxt = sprintf('Normalized squared\n Spearman rho');
xlabel(xtxt);
set(gca,'YTickLabel',names); %Labels for bars.
set(gca,'Position',[0.35, 0.15, 0.60, 0.75]); %Set position of axes within figure
set(gca,'YDir','reverse'); %Plot most influential first
set(gca,'YLim',[0,topN+1]); %Set limits of y-axis to avoid any annoying extra white gap
out = fig;
end
Figure:
% Callback function: SpearmanRunListBox, SpearmanresultsButton
function SpearmanresultsButtonPushed(app, event)
app.plotSpearman(1,30);
end

Answers (1)

Adam Danz
Adam Danz on 3 Feb 2020
Edited: Adam Danz on 6 Feb 2020
You must specify the axis handle in all graphics functions when plotting to a UIAxes in AppDesigner.
Assuming the app's axis handle is app.UIAxes,
barh(app.UIAxes, vals)
title(app.UIAxes,'myTitle')
xlabel(app.UIAxes,'myXLabel')
ylabel(app.UIAxes,'myYlabel')
ylim(app.UIAxes, [0,topN+1])
set(app.UIAxes,'YDir','reverse') % Or app.UIAxes.YDir = 'reverse'
etc.
Also, remove the call to figure() since that is produing an external figure.
Many of the axis properties can be set from within the AppDesigner user interface but you can also set many of those properties from within any function that has access to the axes handle.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!