How to remove discontinuous edges of 3D surf plot?

5 ビュー (過去 30 日間)
Mozhdeh Gholibeigi
Mozhdeh Gholibeigi 2018 年 6 月 2 日
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 件のコメント
Mozhdeh Gholibeigi
Mozhdeh Gholibeigi 2018 年 6 月 2 日
Thanks Jonas for your reply; The reason is that my supervisor wants it in log scale :D I checked the "0" elements of the matrix one-by-one and noticed that some of them seem to have higher values on the Z axis, giving rise to such discontinuity. But for other "0" valued elements it doesn't happen. Can you clarify such behaviour please?
jonas
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
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
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 :)
Mozhdeh Gholibeigi
Mozhdeh Gholibeigi 2018 年 6 月 3 日
Thanks Jonas for your help and guide. I absolutely agree with you and will consider it in my work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by