How to create a custom colormap ("seismic" from python)
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alfredo Scigliani
am 21 Mär. 2023
Bearbeitet: DGM
am 8 Mär. 2025
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 Kommentare
Weitere Antworten (2)
MJFcoNaN
am 21 Mär. 2023
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 Kommentar
Thomas
am 8 Mär. 2025
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
am 8 Mär. 2025
Bearbeitet: DGM
am 8 Mär. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Color and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!