How to remove discontinuous edges of 3D surf plot?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mozhdeh Gholibeigi
el 2 de Jun. de 2018
Comentada: Mozhdeh Gholibeigi
el 3 de Jun. de 2018
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 comentarios
jonas
el 2 de Jun. de 2018
Editada: jonas
el 2 de Jun. de 2018
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.
Respuesta aceptada
jonas
el 2 de Jun. de 2018
Editada: jonas
el 2 de Jun. de 2018
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 comentarios
jonas
el 3 de Jun. de 2018
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 :)
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!