How to create a personalized colormap?

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
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
Matt Fig 2012년 11월 27일
편집: Matt Fig 2012년 11월 27일

0 개 추천

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.

카테고리

도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

질문:

2012년 11월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by