colorbar to vary brightness level given a certain color hue
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Guillaume
il 5 Lug 2016
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
il 5 Lug 2016
Modificato: Image Analyst
il 5 Lug 2016
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 Commenti
Image Analyst
il 6 Lug 2016
Modificato: Image Analyst
il 6 Lug 2016
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.
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!