Set Colorbar TickLabels and TickMarks
561 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Konstantinos Tsitsilonis
el 10 de Ag. de 2017
Comentada: Sebastian Lopez
el 5 de Nov. de 2020
Hi all,
I am having trouble setting my colorbar ticklabels as I wish.
Specifically I have 8 points, and have created a colormap such that these 8 points get values from the darkest to the lightest color in the colormap. Similarly, I would like my colorbar's labels to follow the same pattern. Below is the code that I have written:
cmapdef = colormap(winter) ; %Define Colormap
cmap = cmapdef(1:8:end, :) ; %Find Values of colors corresponding to each point plotted
cbh = colorbar('YTickLabel', num2cell(1:8)) ;
However, the resulting colorbar has labels going as follows: 1 2 3 4 5 6 7 8 1 2 3. Instead I would expect the whole span of the color bar to be covered by 1 2 3 4 5 6 7 8.
What am I doing wrong?
Thanks in advance for your responses,
KMT.
2 comentarios
Konstantinos Tsitsilonis
el 10 de Ag. de 2017
Editada: Konstantinos Tsitsilonis
el 10 de Ag. de 2017
Respuesta aceptada
Konstantinos Tsitsilonis
el 10 de Ag. de 2017
Editada: Konstantinos Tsitsilonis
el 10 de Ag. de 2017
2 comentarios
Más respuestas (1)
José-Luis
el 10 de Ag. de 2017
plot(rand(10,1))
cH = colorbar;
cH.TickLabelInterpreter = 'tex';
idx = 955;
for ii = 1:numel(cH.TickLabels)
cH.TickLabels{ii} = [sprintf('\\color[rgb]{%f,%f,%f} ', rand(1,3)), char(idx)];
idx = idx + 1;
end
You'd need to replace the random color with the actual color you want.
0 comentarios
Ver también
Categorías
Más información sobre Colorbar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!