Matlab image legend with color blocks
我正在尝试为使用
我希望能够设置标签和背景的颜色。使用imshow显示图像,显然
我尝试使用
谁能告诉我应该如何制作这种类型的图例,最好以某种方式使它在调整图形窗口的大小时根据需要浮动并自行移动。如果无法做到这一点,那么有人可以告诉我如何为颜色条的标签文本着色或为颜色条的边框(包含其标签)提供背景颜色吗?如您所见,如果我没有手动添加背景白色框,则标签将不可见。
谢谢。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | label_image = zeros(768, 1024); label_image(100:400, 500:600)=1; label_image(500:600, 100:600)=2; label_image(25:300, 100:400)=3; custom_colormap = [ 0 1 0; 1 0 0; 0 0 1;]; label_image = label2rgb(label_image, custom_colormap, [0 0 0]); % Make a white backround for the colorbar. % Don't want to have to do this line. label_image(25:140, 775:1010,:)=255; % Show the image imshow(label_image, 'InitialMagnification', 50); % Here, I would like to be able to set colorbar label text color and/ or % colorbar bounding box background color, or better yet, use some variant % on the legend function to do this automatically colormap(custom_colormap); labels={'Both', 'Always Moving', 'Moved'}; hcb=colorbar('peer',gca,... [0.7 0.8 0.03 0.1],... 'YTickLabel',labels,... 'XAxisLocation','bottom',... 'TickLength',[0 0],... 'Color',[1 0 1]); |
您要分别设置颜色栏的x和y轴的颜色。
因此,您不必放置白色矩形。 选中