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

조회 수: 4 (최근 30일)
Ethan Samuel
Ethan Samuel 2022년 3월 17일
편집: Dave B 2022년 3월 17일
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.

채택된 답변

Dave B
Dave B 2022년 3월 17일
편집: Dave B 2022년 3월 17일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by