Align colorbar ticks with corresponding colors
8 views (last 30 days)
I have the following script, which plots the corresponding plot. How can I change this so the discrete colors match the used ticks in both the plot and the colorbar? E.g. the dark purple for 14.3-15, then next blueish/purple from 15-16 and so on.
[XI,YI] = meshgrid(x1,y1);
ZI = griddata(x1,y1,z1,XI,YI);
set(gca, 'YScale', 'log');
cbh = colorbar ; %Create Colorbar
cbh.Ticks = [14.3 15 16 17 18 19 20] ; %Create ticks
Sindhu Yerragunta on 18 Jun 2018
This misalignment occurs due to the fact that if suppose there are 10 colors in the colormap, but only 9 bins to put them in.
In general, for a vector containing N ticks, there are N-1 intervals.
In your case reducing the number of colors in the colormap to 7 should help,
Hope this answers the query.