How can I create a colormap with a different colorscale for positive and negative numbers
조회 수: 22 (최근 30일)
이전 댓글 표시
How can I create a colormap with a different colorscale for positive and negative numbers: positive numbers on a white to red scale, and negative numbers on a white to blue scale (zero being white).
댓글 수: 0
답변 (3개)
Sandro Lecci
2018년 6월 19일
편집: Sandro Lecci
2018년 6월 19일
Dear Richard,
a colormap is essentially a nx3 matrix with the specification of RGB (3 columns) and the resolution in n lines. You can either create you own "french flag" (I actually did it by myself in some of my scripts),...
% A french-flag with a resolution of 3 would be:
FF = [0 0 1;...
1 1 1;...
1 0 0];
% which becomes:
FF = [0 0 1;...
0.5 0.5 1;...
1 1 1;...
1 0.5 0.5;...
1 0 0];
% by increasing the resolution.
Follow the instruction on how to use the downloaded file and then retreive the colormap as following:
MyMap = brewermap(100, 'RdBu'); %with 100 being the number of steps in your colormap
myMap = flipud(MyMap); %Since you want blue for negative and red for positive values
Hope this helps. Best
댓글 수: 10
Stephen23
2018년 6월 19일
@Richard Walker: you could:
- create your own colormap which has the white offcenter, or
- specify the colors explicitly when the data is plotted.
There are infinite possible colormaps so it is clearly not feasible for MATLAB to support them all, but it is easy to define your own to suit your data distribution.
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!