Colorbar/varycolor ticks
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi. I'm trying to plot several graphs in the same picture and then identify them by using a vertical colorbar. Each graph corresponds to one value and I'd like the colorbar to have as many colors as there are values and have the same value visible as numbers beside the bar.
The problem is that either only part of the values are shown or the values are in the wrong place. I'm trying to use varycolor.m here, but I'm not sure if it's necessary. Here's what I've tried:
figure(1)
ColorSet = varycolor(length(energia2(:,1)));
set(gca, 'ColorOrder', ColorSet);
hold all;
for k=1:length(energia2(:,1))
plot(thetadeg,M_nostd(:,k))
end
legend off
set(gcf, 'Colormap', ColorSet);
}
% This one prints all the values in the lower part of the colorbar and leaves the rest without numbers (the wanted numbers are from 0 to 5, while the length of the vector is 20)
%colorbar('YTick',energia2(:,1),'YTicklabel',energia2(:,1))
% This has the same problem
%colorbar('YTick',energia2(:,1))
% This one only prints half of the values, but prints them on the whole colorbar area (as I hoped)
colorbar('YTicklabel',energia2(:,1))
I don't understand how this should be done. How do I use colorbar the way I want?
0 comentarios
Respuestas (2)
Sarah Wait Zaranek
el 19 de Abr. de 2011
I believe you don't want to change the ticks but the limits of the axis that contains your colorbar:
h = colorbar; set(h,'Ylim',[0 5])
This will only show the values 0-5 (on the right scale) on your colorbar.
Note that this issue to similar to a question I answered earlier here: http://www.mathworks.com/matlabcentral/answers/5086-rescaling-colormap-colorbar
Edited to contain a difference example:
If you want to set the color order and corresponding colormap - I would suggest this way:
figure;
index = (0:0.25:5);
myMap = colormap(jet(length(index)));
set(0,'DefaultAxesColorOrder',myMap)
hold all
for k=1:length(index)
plot(rand(5,1))
pause(1)
end
hold off
h = colorbar;
set(h,'YTickLabel',num2str(index'));
2 comentarios
Sarah Wait Zaranek
el 19 de Abr. de 2011
This I believe means you need to change the colormap that your colorbar is using - if I understand correctly. I will modify the answer to include that.
Cheers,
Sarah
Irfan Mulla
el 30 de Jul. de 2016
Well, one needs to just add a following line at the end of Jane's code
caxis([min(energia2(:,1)),max(energia2(:,1))])
0 comentarios
Ver también
Categorías
Más información sobre Purple en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!