MATLAB Answers

How do I create a logarithmic scale colormap or colorbar?

조회 수: 1,487(최근 30일)
MathWorks Support Team
MathWorks Support Team 2012년 7월 6일
편집: lvn 2021년 9월 17일 9:37
I need to color 'surf' plots on a log scale and subsequently displace the log-based colorbar.

채택된 답변

lvn 2018년 5월 4일
편집: lvn 2021년 9월 17일 9:37
  댓글 수: 7
Walter Roberson
Walter Roberson 2020년 3월 31일
You can tell by the wording of the official answer that it was written for an older version of MATLAB.

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Berthold Reisz
Berthold Reisz 2019년 3월 15일
Try the following:
% let A be your data
A = 100*rand(100,100);
% plot log10 of 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;
% set Ticks and TickLabels

MathWorks Support Team
MathWorks Support Team 2020년 5월 14일
편집: MathWorks Support Team 2020년 5월 14일
Please follow the steps below to create a log colobar in 'surf' plot:
% Plot the surface plot
[X, Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X, Y, Z)
% Show the colorbar
% Set the log colobar
Note: This feature was introduced in MATLAB R2018a.
For more information, refer to the following documentation page, "Axes Properties":
  댓글 수: 1
Samira Daneshgar
Samira Daneshgar 2017년 1월 12일
Hi, I would like to know how can I apply the same thing for the contourf. Thanks,

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by