Radio button and format of plot axis in app designer and its corresponding plot
4 views (last 30 days)
Show older comments
Carlos Rueda
on 4 Jan 2021
Commented: Carlos Rueda
on 5 Jan 2021
In order to plot the death cases on either both or right Y-axis I used following functions:
yyaxis(app.UIAxes,'left')
yyaxis(app.UIAxes,'right')
The problem now is, how to undo the settings when switching the radio buttons. These functions seem to freeze the display and the deaths curve won't fade away when I switch to show only covid cases, for instance. My default setting for both will not be replaced when I switch to only cases or only deaths (left radio button below):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/478688/image.png)
This is the code I wrote to select the difference cases(plot function):
function plotData(app) %default values missing
%plot data depending on selection from radion buttons
cla reset
if app.ShowCases
yyaxis(app.UIAxes,'left')
app.UIAxes.YLabel.String='Cases';
plot(app.UIAxes,app.TimeLine,app.Positives);
end
if app.ShowDeaths
yyaxis(app.UIAxes,'right')
app.UIAxes.YLabel.String='Deaths';
plot(app.UIAxes,app.TimeLine,app.Deaths);
end
if app.ShowBoth
yyaxis(app.UIAxes,'left')
app.UIAxes.YLabel.String='Cases';
plot(app.UIAxes,app.TimeLine,app.Positives);
yyaxis(app.UIAxes,'right')
app.UIAxes.YLabel.String='Deaths';
plot(app.UIAxes,app.TimeLine,app.Deaths);
end
end
end
And the code I wrote for the event triggering selection from the radio button:
app.ShowCases = app.CasesButton.Value;
app.ShowDeaths = app.DeathsButton.Value;
app.ShowBoth = app.BothButton.Value;
app.plotData;
Without the functions yyaxis(app.UIAxes,'left'/'right') the switch of the plot wil work, but I cannot use the right Y axis though. I have problems to understand the information in the MATLAB documentation and it is not intuitive to found valuable hints by introducing some key words. Thanks in advance to anyone who has a hint for this.
0 Comments
Accepted Answer
Benjamin Kraus
on 5 Jan 2021
Edited: Benjamin Kraus
on 5 Jan 2021
I think the problem you are having is that you are not passing your axes handle into the cla function.
cla(app.UIAxes, 'reset');
As currently written, cla is operating on the "current axes", which is probably not the one in your app. Have you noticed that when that function runs a separate figure window pops open?
Because you are not resetting the axes, when you call plot it is only removing the children from the one side of the yyaxis that is active, rather than resetting the entire axes.
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer 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!