How do I create a logarithmic scale colormap or colorbar?

1,170 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2012 年 7 月 6 日
編集済み: Rena Berman 2023 年 11 月 22 日
I need to color 'surf' plots on a log scale and subsequently displace the log-based colorbar.

採用された回答

MathWorks Support Team
MathWorks Support Team 2023 年 11 月 22 日
編集済み: MathWorks Support Team 2023 年 11 月 22 日
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);
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 following documentation page, "Axes Properties":
https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#budumk7-ColorScale

その他の回答 (2 件)

lvn
lvn 2023 年 11 月 9 日
編集済み: Rena Berman 2023 年 11 月 22 日
  4 件のコメント
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.
Pat Williamson
Pat Williamson 2023 年 5 月 11 日
編集済み: Walter Roberson 2023 年 9 月 5 日
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
Berthold Reisz 2019 年 3 月 15 日
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)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by