How to create a custom colormap ("seismic" from python)
조회 수: 62 (최근 30일)
이전 댓글 표시
I have read the colormap helpdocs but I am in need of a bit of help. I am not so familiar with RGB codes for colors, but I am trying to create a colormap like the one attached. It goes from red to white in the middle and then from white to blue towards the bottom end. How can I achieve something like this?

This specific colormap is called "seismic" in python.
댓글 수: 0
채택된 답변
추가 답변 (2개)
MJFcoNaN
2023년 3월 21일
Hello,
The easiest way may be creating manually in "colormap editor" and then you can save it.
- Right-click the colorbar and select "colormap editor" (I'm not sure the exact English translate).
- You can add/delete/change those key-colors, and Matlab will do the interpolation.
- You may choose the default "jet" colormap as a template. then delete some unwanted key-colors and add a white key-color in the middle.

댓글 수: 1
Thomas
2025년 3월 8일
This was really easy and worked for me. I was also able to save it as a mat file and load it anytime I want now. Thank you!
DGM
2025년 3월 8일
편집: DGM
2025년 3월 8일
Without relying on any external python dependencies, here is an adequately accurate approximation.
n = 256; % specify the length of the generated colortable
x0 = [0 0.25 0.5 0.75 1]; % these are the breakpoint locations (normalized)
CT0 = [0 0 0.3; 0 0 1; 1 1 1; 1 0 0; 0.5 0 0]; % the breakpoint colors
CT = interp1(x0,CT0,linspace(0,1,n)); % the generated color table
% use it for something
peaks(100); % a test plot
colormap(CT)
shading flat
colorbar
clim([-8 8])
This isn't perfectly accurate, but it should be within about 1LSB (in uint8) for map lengths shorter than 512 -- assuming my source is correct. At the very least, it certainly feels a lot more elegant than having the breakpoints all slightly misaligned from such convenient numbers.
EDIT: Of course there are a bunch of different maps all called the same thing. Why did I bother assessing accuracy when it never mattered in the first place?
% this is also "seismic colormap from python"
n = 256; % specify the length of the generated colortable
x0 = [0 0.33 0.4 0.5 0.6 0.667 1];
CT0 = [0.6314 1 1; 0 0 0.749; 0.302 0.302 0.302; 0.8 0.8 0.8; 0.3804 0.2706 0; 0.749 0 0; 1 1 0];
CT = interp1(x0,CT0,linspace(0,1,n)); % the generated color table
% use it for something
peaks(100); % a test plot
colormap(CT)
shading flat
colorbar
clim([-8 8])
Note that within this "seismic colormap" library, there are two relevant colormaps, one literally called "seismic", which has nothing to do with the given example, and one called "RWB", which is roughly similar to, but obviously not the same as the given example.
The first example was specifically taken from MPL, and is probably what's intended. Given the JPG damage and the number of negligibly unique reinventions of the same wheel, it's hard to be certain.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!