How to remove discontinuous edges of 3D surf plot?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a matrix of 30*10 dimension and want to create a surf plot of it such that X and Y are indices of the matrix and matrix elements are plotted on the Z axis. With linear scale for Z axis, the plot looks fine; however, I want the Z axis in logarithmic scale and once I set it via:
set(gca,'ZScale','log')
The surface looks strange and discontinuous at one side (the image is attached); Here is the piece of code to plot the matrix which is attached in a text file:
[X,Y] = meshgrid(1:10,1:30);
figure
surf(X,Y,Z)
colormap parula
shading interp
set(gca,'ZScale','log')
set(gca,'YDir','reverse')
I wonder why does it happen and how it can be fixed? Any help is highly appreciated.
댓글 수: 3
jonas
2018년 6월 2일
편집: jonas
2018년 6월 2일
See for example Z(1)=0. At [x=1;y=1] in your log-scale plot there is no value. Why? Because log(0)=-inf
Add this line to your code and see what happens.
Z(Z<10^-12)=10^-12;
It will substitute all zeros for 10^-12 and your plot will look nice, but the data is manipulated.
Edit: Forgot to mention that some values may appear as 0 because they are extremely small. If you write Z==0, then you will see which values are truly equal to zero.
채택된 답변
jonas
2018년 6월 2일
편집: jonas
2018년 6월 2일
Looks messy because log(0) is undefined. You can manipulate the data a bit and adjust the ZLim to make it look OK. Note that I also split the data set in 3 pieces.
[X,Y] = meshgrid(1:10,1:30);
figure;hold on
Z(Z<10^-5)=10^-5;
h1=surf(X(1:10,:),Y(1:10,:),Z(1:10,1:10))
h2=surf(X(11:20,:),Y(11:20,:),Z(11:20,1:10))
h3=surf(X(21:30,:),Y(21:30,:),Z(21:30,1:10))
colormap parula
set(gca,'ZScale','log')
set(gca,'YDir','reverse')
cb=colorbar
set(gca,'zlim',[10^-5 10^-1])
grid on;box on;
cb.Ruler.Scale = 'log';
cb.Ruler.MinorTick = 'on';
Remove the last two lines if you are running a release older than 2018a
댓글 수: 3
jonas
2018년 6월 3일
When I run my own code I get the attached results, which is a bit different.
"I wonder whether it is also possible to define gradually increasing values..."
Anything is possible, but I would be careful with manipulating the data to make it appear more smooth than it actually is. Setting a definite threshold is OK because you can easily describe what you have done in text or and/or change the last label to (<10^-12).
The most illustrative option might be to use a 2D-perspective, or contourf (see attachment 2). Its often easier to perceive color changes than values from a 3D-perspective.
In the end it's up to you to decide how to best present your data. I can only work with the visual aspects :)
추가 답변 (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!