# plot in logarithmic scale

14 views (last 30 days)
ELISABETTA BILLOTTA on 12 Jan 2022
Commented: Star Strider on 12 Jan 2022
can someone tell me how in a 3d graph I can plot linearly the X and Y axis, while the Z axis (ZZ in this case) to plot it in logarithmic scale?
the command I use is contourf(XX,YY,ZZ,900,'linecolor','none').
thankss

Star Strider on 12 Jan 2022
The contourf function plots a plane, not a surface.
To plot logarithmic contours of the ‘Z’ matrix, it will be necessary to calculate the logarithm of the matrix.
Z = randn(10) % Create Matrix
Z = 10×10
0.3046 -1.9056 -0.6347 -0.6783 0.1703 0.7342 0.4539 0.0859 0.9641 0.7408 -1.3748 -0.7479 0.9053 -1.4477 0.5652 -1.8302 0.2079 -0.4906 -1.0571 1.4710 -1.2717 -1.3417 -0.1471 0.9980 0.7213 -0.1074 -2.5673 1.4666 -0.0245 0.7185 1.6482 -0.7584 -0.2463 0.0507 -0.8587 -1.6823 -0.1376 1.7483 -0.7345 -0.3289 0.5851 0.8130 0.1395 0.1867 -1.4069 0.4896 1.4678 -0.0682 -2.6445 1.3236 1.7016 -0.7192 0.0310 -0.6274 -0.4594 -0.7578 -0.0915 0.4802 1.0584 -0.2711 0.0377 0.7731 -0.6610 -1.5448 -1.4279 -0.0605 -0.5192 0.4518 -2.2159 -0.5416 -0.1186 -0.6605 -0.4166 -0.9430 2.7231 1.0224 -0.0210 0.2174 -0.1919 -0.2458 -0.8351 -0.4570 0.2475 -0.4197 0.9497 1.2172 0.6185 1.3550 0.5498 -0.1129 0.2521 1.3799 -0.2456 -0.8516 -0.2364 -0.6204 -0.5317 -0.3331 -0.4287 1.7901
figure
contourf(Z)
colormap(turbo(10))
colorbar
title('\$Original\ Z\$', 'Interpreter','latex')
figure
contourf(log(abs(Z))) % Logarithms Of The Absolute Values
colormap(turbo(10))
colorbar
title('\$log(|Z|)\$', 'Interpreter','latex')
Zs = Z;
Zs(Zs<=0) = NaN; % 'NaN' Values Do Not Plot, log(NaN)= NaN
figure
contourf(Zs)
colormap(turbo(10))
colorbar
title('\$log(Z > 0)\$', 'Interpreter','latex')
.
##### 2 CommentsShowHide 1 older comment
Star Strider on 12 Jan 2022
I can probably make it work if I have your data and the relevant part of the code.
Using synthetic data —
x = 0:9;
y = 4:13;
z = randn(10);
figure
contourf(x, y, log(abs(z)))
colormap(turbo(10))
colorbar
So it definitely can work with linear ‘x’ and ‘y’ vectors (or matrices created from them using ndgrid or meshgrid).
.

Simon Chan on 12 Jan 2022
I think you may need to use function contour3.
Then you can set the Z-axis scale to log by
set(gca,'ZScale','log')
ELISABETTA BILLOTTA on 12 Jan 2022
with contour3 the graph I need is not displayed