colorbar for specified color

조회 수: 1 (최근 30일)
Yu Li
Yu Li 2018년 9월 28일
편집: jonas 2018년 9월 28일
Hi:
I want to add a colorbar in Matlab like below:
is there anyway to do this in Matlab?
Thanks!
Yu

채택된 답변

jonas
jonas 2018년 9월 28일
편집: jonas 2018년 9월 28일
Based on the data and code given below in the comments, you can build a custom colorbar with textboxes. The result is quite nice!
The below code shows the steps involved, however it cannot be executed without adding it to the code which is provided by OP in the comments.
p=cbp.Position;
w=p(3)/numel(sg)
cmap=colormap(jet(length(sg)))
str=sprintfc('\n Class %g',1:numel(sg))
for i=1:numel(sg)
annotation('textbox',[p(1)+w*(i-1) p(2) w*0.95 p(4)],'backgroundcolor',cmap(i,:),'string',str{i})
end
  댓글 수: 8
Yu Li
Yu Li 2018년 9월 28일
편집: Yu Li 2018년 9월 28일
fantastic, thank you very much.
Please revise your first answer with this one, to let other people easier to find this answer. and I'll accept it after you revise it.
jonas
jonas 2018년 9월 28일
Happy to help! Yes, I was going to do that but wanted to wait until you were satisfied :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by