如何设置颜色条标签 [英] How to set colorbar labels
问题描述
我在喷射"配色图中有几点.这些点的系数可以从0到1,但是通常它们不能覆盖所有范围,例如0.75-0.9.
I have some points in a 'jet' colormap. The points have a coefficient that can go from 0 to 1, but usually they dont cover all the range, e.g 0.75-0.9.
当我绘制这些点时,我会为其着色,因此0.75是颜色图中的次要颜色,而0.9是颜色图中的最大颜色,因此将显示所有颜色图.我想做的就是在颜色栏中也显示出来.当我绘制颜色条时,其上的标签会变为64,但是我希望它们的范围从0.75到0.9.我该怎么办?
When I plot those points I colour them so 0.75 is the lesser colour in the colormap and 0.9 is the maximum color in the colormap, so all the colormap is shown. What I want to do is show that in the colorbar also. When I plot the colorbar the labels on it go to 64, but I want them from 0.75 to 0.9. How can I do that?
编辑
我认为代码本身并没有多大帮助,但以防万一.在colors
变量中,将ZNCC
转换为颜色图的范围.
EDIT
I don't think the code itself helps a lot but here it goes, just in case. In the colors
variable I convert the ZNCC
to the range of the colormap.
EDIT2
我找到了caxis
对我不起作用的原因.这是代码:
I found the reason why caxis
is not working for me. Here is the code:
%this is why it doesnt work
im=imread('someimageyouwanttotest_inRGB.png')
imshow(im)
points=[1, 2;1 , 2 ;0.3,0.7]
ZNCC=points(3,:)
cmap=colormap('jet');
colors=cmap(round( ((1-min(ZNCC))+ZNCC-1).*(size(cmap,1)-1)/max((1-min(ZNCC))+ZNCC-1))+1,: );
hold on
for i=1:length(ZNCC)
plot(points(1,i),points(2,i),'.','Color',colors(i,:));
end
colorbar()
hold off
推荐答案
我认为这是您的代码正确显示了所有颜色,然后只在没有图像的情况下首先设置了颜色栏:
I think that is your code displays all your colours correctly then rather just set up the colour bar first on no image:
points=[1, 2;1 , 2 ;0.3,0.7]
ZNCC=points(3,:)
cmap=colormap('jet');
caxis([min(ZNCC) max(ZNCC)]);
colorbar();
hold on
%this is why it doesnt work
im=imread('someimageyouwanttotest_inRGB.png')
imshow(im)
colors=cmap(round( ((1-min(ZNCC))+ZNCC-1).*(size(cmap,1)-1)/max((1-min(ZNCC))+ZNCC-1))+1,: );
for i=1:length(ZNCC)
plot(points(1,i),points(2,i),'.','Color',colors(i,:));
end
hold off
我没有imshow
:/
这篇关于如何设置颜色条标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!