Replotting a 2D graph on a 3D surface keeps all 3 axes
7 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!