![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196763/image.jpeg)
colorbar for specified color
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi:
I want to add a colorbar in Matlab like below:
is there anyway to do this in Matlab?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196746/image.jpeg)
Thanks!
Yu
0 commentaires
Réponse acceptée
jonas
le 28 Sep 2018
Modifié(e) : jonas
le 28 Sep 2018
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196763/image.jpeg)
8 commentaires
jonas
le 28 Sep 2018
Happy to help! Yes, I was going to do that but wanted to wait until you were satisfied :)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!