colorbar to vary brightness level given a certain color hue
조회 수: 2 (최근 30일)
이전 댓글 표시
I use the following code to produce these types of 2D histograms, one for each of several conditions:
matrix = [ratingsx(:) ratingsy(:)];
values = hist3(matrix,[7 7]);
values = values';
imagesc(values)
colorbar('Ticks',[0 max(max(values))], 'TickLabels',{'0',[num2str(max(max(values)))]})
colormap gray;
Right now the colorbars are all greyscale across all conditions, but in fact each condition has had, in a previous graph, a different colour associated with it (e.g. "Classical"=red, "Random"=yellow, etc), and I would like the colourbars to reflect that respective hue, i.e. go from dark red to light red for "Classical" etc.
How can I achieve that? Many thanks!
댓글 수: 0
답변 (2개)
Guillaume
2016년 7월 5일
As you said, you want to replace the hue. So, grab the grey colour map, convert to HSV (Hue, Saturation, Value), replace the grey hue by whichever hue you want, and convert it back to RGB. Because, the saturation is also 0 in the gray colour map, you also need to increase it.
originalrgb = [0.5 0.3 0.7]; %replace by whatever rgb colour you want
originalhsv = rgb2hsv(originalrgb); %get the HSV values of your original colour. We really only care about the hue
maphsv = rgb2hsv(gray); %without any argument gray returns 64 values; convert to hsv
maphsv(:, 1) = originalhsv(1); %replace gray hue by original hue
maphsv(:, 2) = originalhsv(2); %replace saturation. Anything but 0 will work
newmap = hsv2rgb(maphsv);
colormap(newmap);
Image Analyst
2016년 7월 5일
편집: Image Analyst
2016년 7월 5일
Take your original colormap and see if there are any constant hues in there. There may not be any, so you'd have to construct such a colormap. I suggest you therefore create the colormap in hsv color space, then use hsv2rgb() to map it back to RGB colors, then use colormap() to apply that RGB colormap to your axes. Construct the HSV colormap with the first column being the hues, the second column being the saturation, and the third column being the value. You probably want the saturation column to be all 1's. Then for each hue, use linspace() to get a series of step values in the value component (the 3rd column). How many hues do you want, and for each hue, how many brightness steps do you want?
댓글 수: 2
Image Analyst
2016년 7월 6일
편집: Image Analyst
2016년 7월 6일
If you post your data, and say how many hues you want and what data value range each hue should dover, and how many darknesses for each hue you want, I might be able to try some things. For example, let's say your data is continuous values between 0 and 90 and you want 0-30 to be different lightnesses of red, 30-60 to be different darknesses of yellow, and 60-90 to be different darknesses of green. And for each hue, you want 4 different darknesses. Or whatever. You have to let me know what the color map should be so I can figure out how to create it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!