![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288135/image.png)
How to customize color map
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi I want to plot temperature and precipiation anomlies from positive to negative values. I plotted that using pcolorm : ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288117/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288117/image.jpeg)
But the problem is I want to plot anomaly = 0 to be White not green. So positive anomaly should be in yellow orange and red and the negative anomaly in bleu colors.
This is how my teacher did and It should look like this: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288118/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288118/image.png)
Also I only want to plot regions between lattitude 30 N to 30 S so how can I do this?
Thnaks
댓글 수: 0
답변 (2개)
Image Analyst
2020년 4월 28일
Try this. First we figure out what the colormap looks like using the sample image. Then we know how to build it and we can use linspace(), ones(), and zeros() to build a perfect one that we can apply to any image.
% Let see what this map looks like by examining the sample image.
hFig = figure;
fontSize = 20;
rgbImage = imread('image.png');
subplot(3, 1, 1);
imshow(rgbImage);
axis('on', 'image');
impixelinfo
redMap = rgbImage(18:122, 280, 1);
greenMap = rgbImage(18:122, 280, 2);
blueMap = rgbImage(18:122, 280, 3);
plot(redMap, 'r-', 'LineWidth', 2);
hold on;
plot(greenMap, 'g-', 'LineWidth', 2);
plot(blueMap, 'b-', 'LineWidth', 2);
legend('Red', 'Green', 'Blue', 'Location', 'southeast');
grid on;
title('Colormap from Sample image', 'FontSize', fontSize);
% Synthesize a similar "perfect" colormap.
% You don't need the sample image anymore - that was just to figure out how we could build this colormap.
numColors = 64; % An even number!
c4 = numColors/4;
redMap = [linspace(125, 255, c4), 255 * ones(1, c4), linspace(255, 0, c4), zeros(1, c4)] / 255;
greenMap = [zeros(1, c4), linspace(0, 255, c4), linspace(255, 0, c4), zeros(1, c4)] / 255;
blueMap = fliplr(redMap);
cMap = [redMap(:), greenMap(:), blueMap(:)];
subplot(3, 1, 2);
plot(redMap, 'r-', 'LineWidth', 2);
hold on;
plot(greenMap, 'g-', 'LineWidth', 2);
plot(blueMap, 'b-', 'LineWidth', 2);
legend('Red', 'Green', 'Blue', 'Location', 'southeast');
grid on;
title('Regenerated Colormap', 'FontSize', fontSize);
% Read in a gray scale image that we can apply the colormap to.
grayImage = imread('cameraman.tif');
subplot(3, 1, 3);
imshow(grayImage);
axis('on', 'image');
impixelinfo
title('Regenerated Colormap', 'FontSize', fontSize);
% Apply it to the image.
colormap(cMap);
colorbar;
hFig.WindowState = 'maximized';
fprintf('Done running %s.m.\n', mfilename);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288135/image.png)
댓글 수: 0
Olawale Ikuyajolu
2020년 4월 28일
r = -8 + (8+4)*rand(10); %generate random number between -8 and 4
pcolor(r);shading interp;
%% what you need starts from here
caxis([-8 4]) % set your colorbar limits
myColorMap = jet(24); %Each number takes two color values (we have 12 points between -8 and 4)
colorbar
myColorMap(16:17,:) = 1; % set the color around zero to white
colormap(myColorMap)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288175/image.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Blue에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!