Colorbar/varycolor ticks
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Sarah Wait Zaranek
2011년 4월 19일
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
Sarah Wait Zaranek
2011년 4월 19일
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
2016년 7월 30일
Well, one needs to just add a following line at the end of Jane's code
caxis([min(energia2(:,1)),max(energia2(:,1))])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Colorbar에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!