修改色条刻度和颜色范围 [英] Modify colorbar ticks and color range
问题描述
此问题是先前有关 在示例中,您可以看到彩条覆盖了整个hsv范围,并且刻度从0到1. 我想要的是仅显示hsv范围的高75%,刻度从0到max(A(:)) 假定max(A(:))= 0.35的正确颜色条应如下所示:
(您可以看到我只是裁剪了它,但这也不是必须的) 要做到这一点,您需要做两件事.首先裁剪颜色条,然后设置其极限.其次,更改文本框标签中的文本,但是要确保它们位于正确的位置,您还需要手动设置它们的位置.希望代码有意义: This question is following on from a previous question about HSV color space. Let's say I have two arrays When displaying First difficulty that I'm facing is that I want my Hue to be in the interval Second difficulty is that I need to match the value range from Example code: In the example you can see that the colourbar covers the whole hsv range and has ticks from 0 - 1. What I want it to be is showing only the upper 75% of the hsv range with ticks from 0 to max(A(:)) The correct colorbar assuming that max(A(:)) = 0.35 should look like this:
(you can see that I just cropped it, but that should not be necessary either) In order to do that you need 2 things. First crop the colorbar, bu setting its limits. Secondly, change the text in the labels of the colobar, but to make sure they are in the rigth places, you also need to set the positions of them manually. Hopefully the code makes sense: 这篇关于修改色条刻度和颜色范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!cb = colorbar();
set(cb, 'ylim', [25 100])
set(cb, 'XTick', [25:15:100]) % modify values if you preffer
set(cb,'XTickLabel',strsplit(num2str([0.25:0.15:1])));
A
and B
, where A
are my data points (2D) of interest to be shown in the colorbar and B
is an RGB image transformed from the HSV color space where: Hue is in the interval [0.25-1]
(corresponding to normalized A
values 0.25-1), Saturation = 1, Value in interval [0-1]
(corresponding to some other values).B
with imshow
, I want to create a matching colorbar with ticks that correspond to the value range from A
.[0.25-1]
and hence I only need a certain part of the hsv
colorbar to be displayed.A
to the colorbar.
A = rand(30,30)*0.4; % Values range from 0 - 0.4
X = rand(30,30)*100+100; % Values range from 100 - 200
A_n = A / (max(A(:))/0.75) + 0.25; % "Normalize", with range 0.25 - 1
X_n = X / max(X(:)); % Normalize, range 0 - 1
colorRGB = NaN([size(A),3]); % preallocate
for ii = 1:size(A,1)
for jj = 1:size(A,2)
colorRGB(ii,jj,:) = hsv2rgb([A_n(ii,jj),1,X_n(ii,jj)]); % turn into RGB
end
end
imshow(colorRGB), % display image
colormap hsv; cb = colorbar();
cb = colorbar();
set(cb, 'ylim', [25 100])
set(cb, 'XTick', [25:15:100]) % modify values if you preffer
set(cb,'XTickLabel',strsplit(num2str([0.25:0.15:1])));