I've developed a new R,G,B colormap of 15 entries based on my data. These entries varying in the range [0.0,1.0]
in a monotonically growing sequence and represent the value of a parameter P to which 15 samples are associated. For instance, 3 pairs (P,sample number) would be (0.0,266); (0.5,262); (1.0,276)
.
Problem: I wish that P appear from red to blue in the colorbar, but that the 'ticks' mark the numbers for the 15 samples.
It's discussed in this post how to manipulate the colorbar's 'YTickLabel'.
In this second post from MathWorks , the solution to change the amount of ticks is readily achieved by calling the colorbar handle cbr
and using set(cbr,'YTick',20:2:50)
- as discussed therein. However, sounds to me that both ways are fine since the the data are monotonic and with small amount of ticks.
In my case, P grows monotonically, but the sample numbers associated to them do not. Also, there are 15 ticks.
Then, someone has a suggestion on how can I have these 15 tick marks correctly placed and working together with the location 'southoutside' to have the colorbar in the horizontal?
My attempts are below: For both cases, colorbar didn't print more than 8 ticks. I had no success with 'YTick' too, since the sample numbers are not monotonic.
More "fancy" way:
samplex = [ 266, 267, 265, ..., 262, 276 ]; % vector of 15 sample numbers sx = num2str(samplex); sx = cellstr(sx); hx = colorbar; set(hx,'YTickLabel',sx)
Add point by point
hx = colorbar; set(hx,'YTickLabel',{'266','262',...,'276'})
Colormap matrix: this is my colormap matrix named CX
in format short
:
CX =
0.5397 0 0
1.0000 0.4603 0
1.0000 0.5714 0
0.4603 1.0000 0.5397
0.4286 1.0000 0.5714
0 0.9206 1.0000
0 0.2857 1.0000
0 0.1905 1.0000
0 0.1905 1.0000
0 0.0476 1.0000
0 0 0.9683
0 0 0.9683
0 0 0.9524
0 0 0.7143
0 0 0.5079
Then, I use
cx = colormap(CX);
axis off;
set(gcf,'color','None');
before the set
commands quoted in my attempts.
Thank you for any help.
Remark: I just need to set up the colorbar and export it to a .pdf afterwards, with no background color, figures or axes. This step is OK. Here is an example figure: