Setting the Z limits of a scatter3 plot

조회 수: 21 (최근 30일)
Feri
Feri 2020년 3월 27일
댓글: Ameer Hamza 2020년 3월 27일
Hello,
I have a scatter3 plot of an sphere with its center at (0, 0, 0) and its readius equal to 50. I am showing this in a scatter plot; so the Z limits are from -50 to 50. Now what I want to do is to only show the Z values that are larger than -10 and smaller than 20. I dont want to select these data points in a loop and then replot them. Rather setting the Zlim = ([-10 20]) does the job, but it rescales the entire plot in Z direction (whick makes sense).
Is the any way to keep the original Z limits, ([-50 50]), but only show the data that is above -10 and below 20?
(I hope I was able to explain what my issue is).
Any help is much appreciated.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 27일
편집: Ameer Hamza 2020년 3월 27일
Run this example
fig = figure;
[X,Y,Z] = sphere(50);
x = 50*X(:);
y = 50*Y(:);
z = 50*Z(:);
z(z>20) = nan;
z(z<-10) = nan;
scatter3(x,y,z, '.')
zlim([-50, 50]);
  댓글 수: 2
Feri
Feri 2020년 3월 27일
Thank you Ameer,
Yes, I know of this solution, but since the size of the data set is large, (2.5 million data points) this might take some time. However, it seems that there is no solution to this.
Thank you so much anyways.
Ameer Hamza
Ameer Hamza 2020년 3월 27일
yes, I need to filter these elements, either by setting them to nan or deleting them. I think setting them to nan is the faster of these two solutions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by