How to create a personalized colormap?
5 次查看(过去 30 天)
显示 更早的评论
I would like to create a colormap function which takes in a value from say 0 to 100 and return a color, which I can then use in plot/patch functions. I'd need the color to go from white to e.g. red, but if you can provide a general example it's even better.
Thanks for any tip!
1 个评论
Image Analyst
2012-11-28
编辑:Image Analyst
2012-11-28
How about
myColormap = flipud(hot(100))
indexes start at 1. If you need to start at 0 just add one before you get the actual index.
回答(1 个)
Matt Fig
2012-11-27
编辑:Matt Fig
2012-11-27
You can easily do it. Make the surface go from white to red as you say...
peaks(100);
set(findobj('type','surf'),'edgecolor','none')
CM = [ones(1,100);linspace(0,1);linspace(0,1)].';
set(gcf,'colormap',CM)
% Or, set(gcf,'colormap',flipud(CM))
So to use a colormap you just need an m-by-3 matrix. Each row is a color that will be indexed into by surfaces, etc. To find out more, look at the documentation for colormap.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!