How do I create a logarithmic scale colormap or colorbar?
591 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 6 de Jul. de 2012
Editada: MathWorks Support Team
el 4 de Abr. de 2025
I need to color 'surf' plots on a log scale and subsequently displace the log-based colorbar.
Respuesta aceptada
MathWorks Support Team
el 3 de Abr. de 2025
Editada: MathWorks Support Team
el 4 de Abr. de 2025
Please follow the steps below to create a log colorbar in a 'surf' plot:
% Plot the surface plot
[X, Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
figure;
surf(X, Y, Z)
% Show the colorbar
colorbar
% Set the log colobar
set(gca,'ColorScale','log')
Note: This feature was introduced in MATLAB R2018a.
For more information, refer to the "Color and Transparency Maps" section of the Axes Properties documentation:
6 comentarios
Walter Roberson
el 21 de Mzo. de 2025
@MathWorks Support Team does not (usually) read these posts.
Guy
el 4 de Abr. de 2025
Thank you for pointing out this behavior of "colorbar" limits. A request has been made to the MathWorks development team to document specifically how the limits of a "colorbar" are determined.
Más respuestas (2)
lvn
el 9 de Nov. de 2023
Editada: Rena Berman
el 22 de Nov. de 2023
set(gca,'ColorScale','log')
4 comentarios
Walter Roberson
el 31 de Mzo. de 2020
You can tell by the wording of the official answer that it was written for an older version of MATLAB.
Pat Williamson
el 11 de Mayo de 2023
Editada: Walter Roberson
el 5 de Sept. de 2023
Hi Kristoffer Walker,
If you still need assistance with this issue, please create a MathWorks Technical Support Case. We would be happy to help you out.
Berthold Reisz
el 15 de Mzo. de 2019
Try the following:
% let A be your data
A = 100*rand(100,100);
% plot log10 of A
pcolor(log10(A))
% get the minimum and maximum value of A
c1 = min(min(A));
c2 = max(max(A));
% set limits for the caxis
caxis([log10(c1) log10(c2)]);
% preallocate Ticks and TickLabels
num_of_ticks = 5;
Ticks = zeros(1,num_of_ticks);
TickLabels = zeros(1,num_of_ticks);
% distribute Ticks and TickLabels
for n = 1:1:num_of_ticks
Ticks(n) = log10(round(c2)/num_of_ticks*n);
TickLabels(n) = round(c2)/num_of_ticks*n;
end
% set Ticks and TickLabels
colorbar('Ticks',Ticks,'TickLabels',TickLabels)
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution 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!
