Unable to set ticks on a colorbar

조회 수: 18 (최근 30일)
A LL
A LL 2022년 1월 17일
댓글: A LL 2022년 1월 18일
I am unable to define ticks on my colorbar.
I want to plot the figure shown below with ticks at [1002 1004 1006 1008 1010 1012 1014 1016 1018].
I tried the command
cb = colorbar('YTick',1002:2:1018);
and
cb.Ticks=[1002:2:1018];
But it does not work and the ticks remain from 1004 to 1012.
Here is my code:
figure(1);
hold on;
axesm('MapProjection','eqdazim','MapLatLimit',[60 90]);
axis off;
framem on;
gridm on;
mlabel on;
plabel on;
setm(gca,'MLabelParallel',0);
pcolorm(ERAlat,ERAlon,data); %ERAlat, ERAlon and data files are attached
colormap(parula);
cb=colorbar;
%cb = colorbar('YTick',1002:2:1018); %I tried this command but does not work
%cb.Ticks=[1002:2:1018]; %I tried this command but does not work
cb.Ticks=test;
geoshow('landareas.shp','FaceColor',"none",'LineWidth',1);
set(gca,'Fontsize',15);
gcf;
How should I write my script to be able to have the ticks define as I want i.e. [1002:2:1018]?
Thank you
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 1월 17일
I would have expected
cb.Ticks=[1002:2:1018];
to work, provided that those values were within the caxis limits.
A LL
A LL 2022년 1월 17일
Is there a way to fix my issue?

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

채택된 답변

Dave B
Dave B 2022년 1월 17일
편집: Dave B 2022년 1월 17일
If you want your color to range from 1002 to 1018:
caxis([1002 1018])
% or set(gca,'CLim',[1002 1018])
This will let you label the ticks as expected - the key idea here is that the ticks of the colorbar and limits for the color axis are independent.
  댓글 수: 1
A LL
A LL 2022년 1월 18일
It works, thank you very much
I will keep that in mind!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by