How to display colorbar with unevenly spaced colors on a colorbar with each color interval of equal size?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello folks,
I have some data that I want to display with a matlab filled contour plot. The colors are based on a concentration that ranges from 0 to 50, but it is important to see the differences between the low concentrations in more detail than the higher concentrations. The data does not get log transformed. I wrote some code to set the colorbar with the desired intervals, but I want the colorbar to display with all intervals being of equal size.
cmap = [ repmat([1 1 1],100,1) % < 0
repmat([225 225 225]./255,33,1) % 0 - 0.33
repmat([178 178 178]./255,67,1) % 0.33 - 1
repmat([130 130 130]./255,150,1) % 1 - 2.5
repmat([78 78 78]./255,250,1) % 2.5 - 5
repmat([115 223 255]./255,600,1) % 5 - 11
repmat([0 112 255]./255,1200,1) % 11 - 23
repmat([255 255 0]./255,1200,1) % 23 - 35
repmat([255 170 0]./255,1500,1) % 35 - 50
repmat([255 0 0]./255,2000,1) % > 50
];
t = [-1 0 0.33 1 2.5 5 11 23 35 70];
[c,h] = contourf(X,Y,V);
set(h,'edgecolor','k','levellist',t)
colormap(cmap)
caxis([t(1) t(length(t))]);
colorbar('FontSize',11,'YTick',(t),'YTickLabel',t);
Any help on this would be greatly appreciated!
Thanks, Melissa
0 Kommentare
Antworten (1)
Adam
am 30 Jun. 2017
cmap = [ repmat([1 1 1],100,1) % < 0
repmat([225 225 225]./255,33,1) % 0 - 0.33
repmat([178 178 178]./255,100,1) % 0.33 - 1
repmat([130 130 130]./255,250,1) % 1 - 2.5
repmat([78 78 78]./255,500,1) % 2.5 - 5
repmat([115 223 255]./255,1100,1) % 5 - 11
repmat([0 112 255]./255,2300,1) % 11 - 23
repmat([255 255 0]./255,3500,1) % 23 - 35
repmat([255 170 0]./255,5000,1) % 35 - 50
repmat([255 0 0]./255,5001,1) % > 50
];
should give you more what you are looking for I think. The relative amount of each colour band in the colourbar needs to match the amount of data so that it maps correctly, you can't have a linear colourbar and non-linear data ranges to map onto it.
You can play around with the last bin with any value you want > 5000, depending how big you want that last band of colour to be.
2 Kommentare
Adam
am 30 Jun. 2017
This colourmap ought to colour your plot correctly though at least (I only did a quick check with random data, but it seemed to). You may have to create custom graphics for showing what colour represents what range though if you don't like the colourbar.
This is easy enough with some small axes with a coloured patch or just axes background colour and a text label next to each.
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!