修改色条刻度和颜色范围 [英] Modify colorbar ticks and color range

查看:267
本文介绍了修改色条刻度和颜色范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是先前有关

在示例中,您可以看到彩条覆盖了整个hsv范围,并且刻度从0到1.

我想要的是仅显示hsv范围的高75%,刻度从0到max(A(:))

假定max(A(:))= 0.35的正确颜色条应如下所示:

(您可以看到我只是裁剪了它,但这也不是必须的)

解决方案

要做到这一点,您需要做两件事.首先裁剪颜色条,然后设置其极限.其次,更改文本框标签中的文本,但是要确保它们位于正确的位置,您还需要手动设置它们的位置.希望代码有意义:

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])));

This question is following on from a previous question about HSV color space.

Let's say I have two arrays 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).

When displaying B with imshow, I want to create a matching colorbar with ticks that correspond to the value range from A.

First difficulty that I'm facing is that I want my Hue to be in the interval [0.25-1] and hence I only need a certain part of the hsv colorbar to be displayed.

Second difficulty is that I need to match the value range from A to the colorbar.


Example code:

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(); 

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:

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])));

这篇关于修改色条刻度和颜色范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆