Effacer les filtres
Effacer les filtres

Replotting a 2D graph on a 3D surface keeps all 3 axes

10 vues (au cours des 30 derniers jours)
Ethan Samuel
Ethan Samuel le 17 Mar 2022
Modifié(e) : Dave B le 17 Mar 2022
Using app designer, I have one UIAxis that allows the user to switch between a 2D line plot and a 3D surface plot. When switching from the 3D plot to the 2D plot the z-axis remains which it is not supposed to. The user should be able to switch between as much as they want.
cla(app.UIAxes);
if app.DButton.Value == 1 % 2D check selected
plot(app.UIAxes,app.xaxis,app.yaxis) % plot 2 graph
app.graph = app.UIAxes.Children;
else % else 3D check selected
[X,Y] = meshgrid(app.xaxis,app.yaxis);
[Z] = meshgrid(app.zaxis);
surf(app.UIAxes,X,Y,Z) % 3D surface plot
end
I'm using cla(app.UIAxes) to reset the axis every time the radiobutton is changed but for some reason the plot is keeping the z-axis even though the code has plot(x,y).
It's supposed to be:
What is actually being plot:
Any help would be appreciated.

Réponse acceptée

Dave B
Dave B le 17 Mar 2022
Modifié(e) : Dave B le 17 Mar 2022
cla doesn't reset the view.
Here are some options:
Set the view explicitly: view(app.UIAxes, 2)
Call cla with the reset flag, which will reset the axes to its original state (including getting rid of the labels and other things you've done to configure it): cla(app.UIAxes ,'reset')
Note the presence/absence of the grid in the examples below, surf turns on the grid (if you haven't set it explicitly elsewhere), cla doesn't turn it off, but cla('reset') does.
figure;
surf(peaks);xlabel('x');cla
figure;
surf(peaks);xlabel('x');cla('reset')
figure;
surf(peaks);xlabel('x');cla;view(2)

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by