How to customize Colorbar on map?
31 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone! I'm trying to recreate the Colorbar below. As you can see, the colorbar goes by increments of 0.01 until it gets to 0.1, then by 0.1 until it get to 1, and then values of 1 until it gets to 10, and so on. So a value around 2 would be colored as Orange on the plot.

I'm having trouble recreating this sort of colorbar.
My code:
figure(1)
load coastlines.mat
worldmap([min(lat) max(lat)], [min(lon) max(lon)])
contourfm(lat,lon,chlor_a); hold on
geoshow(coastlat,coastlon,'Color','k','LineWidth',3)
%set colorbar to match NASA's
colormap(jet)
h=colorbar;
%colormap(jet)
h.Label.String='Chlor-a (mg m^-3)';
h.Label.FontSize=10;
clim([0.01 20]) %use NASA's color scale
title('Map of Chlorophyll-a Concentration off California Coast (07/12/2022 - 07/19/2022)')
How would I change the increments in the limits?
0 件のコメント
回答 (2 件)
Sulaymon Eshkabilov
2023 年 1 月 13 日
If you want to change a tickmarks only, then :
[X,Y] = meshgrid(-7:.25:7.5);
Z1 = X.^2 + Y.^2;
Z2 = Z1 + 10;
figure
surf(X,Y,Z1);
colorbar('Ticks', 0:20:100)
hold on
0 件のコメント
DGM
2023 年 1 月 13 日
編集済み: DGM
2023 年 1 月 13 日
You should be able to set the axes colorscale to log.
% some fake data
x = linspace(0,1,100);
y = x.';
Z = 20*10.^(y-1) .* x;
% plot it somehow
pcolor(Z);
shading flat
colormap(jet)
% set up a colorbar with log scale
cb = colorbar;
set(gca,'colorscale','log')
cb.Ticks = [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20];
caxis([0.01 20])
If you additionally want to recreate the same colormap and don't know what it is, you can approximate it.
% read image and process it
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1261675/image.png');
rect = [92 79 991 33];
A = imcrop(A,rect);
CT0 = permute(mean(im2double(A),1),[2 3 1]);
CT0 = CT0([true; ~all(diff(CT0,1,1)==0,2)],:); % remove duplicate rows
% CT0 is now a fixed-length color table
% make it whatever length we want
N = 256; % specify the number of colors in table
na = size(CT0,1);
CT = interp1(linspace(0,1,na),CT0,linspace(0,1,N));
% then plot as before
figure
pcolor(Z);
shading flat
colormap(CT)
% set up a colorbar with log scale
cb = colorbar;
set(gca,'colorscale','log')
cb.Ticks = [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20];
caxis([0.01 20])
The difference is subtle, but I figured I'd add the option. Bottom is jet(256); top is the map taken from the image.

0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Purple についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!