Is it possible to use the colormap "Purples" in MATLAB, which maps zeros to white?

24 Ansichten (letzte 30 Tage)
Dear MATLAB users,
Using the colormap "Purples" in Matplotlib (See: https://matplotlib.org/stable/tutorials/colors/colormaps.html) the zero values are displayed as white intensities. Is it possible to use such colormap in MATLAB?
Here you could find some colormaps in Matplotlib, which display zeros as white intensities:
Thanks for your help!

Akzeptierte Antwort

John D'Errico
John D'Errico am 28 Nov. 2021
Bearbeitet: John D'Errico am 28 Nov. 2021
Um, trivially, yes. (Ok, maybe not trivial. But not difficult.) The biggest question is just to recognize what you want to call purple. Your choice might play around with the red versus blue contribution in p.
First is to understand what color is white? White is the color [1,1,1] (scaled 0 to 1.)
Next, what is purple? I suppose there are different things you might call purple. A quick check with this page:
suggests you might want what they called an indigo variation of purple, assuming you want a match to the purple colormap shown in your picture. Something like [75 0 130]/255 seems about right. But there are certainly other variations of what one might call purple.
So how do we make a color map? Simple.
n = 100; % the number of levels in said colormap
t = linspace(0,1,n)';
w = [1 1 1];
p = [75 0 130]/255; % rescale 8 bit colors into [0,1].
CM = (1-t)*w + t*p;
colormap(CM)
pcolor(repmat(0:100,[20,1]))
shading interp
Your colormap is now purples. I am green with envy. But that would be a horse of another color. ;-)
Oh. One other point of interest (in this case, a real one in my eyes) is that IF you intend to print such an image, then it is good to know that IF the colors in your image will be out of gamut for the printer you will be using, then many color printers tend to turn bright blues a bit purplish and so purples might also move around a bit. This because of gamut mapping issues and interactions with how those colors are represented and how the printer drivers will move those colors around in color spaces. Purple is an interesting color in this context. But that really is a horse of a completely different color, and probably way off topic.
  2 Kommentare
qilin guo
qilin guo am 28 Nov. 2021
hhh, dear John D'Errico, thank you very much! It really helps me! and now I also know how to generate my own colormaps!
John D'Errico
John D'Errico am 28 Nov. 2021
Bearbeitet: John D'Errico am 28 Nov. 2021
Yes. That trick would work to generate any colormap with two given end points. You could even tweak things around to put a third color in the middle, by joining two colormaps top to bottom. So a colormap could be designed to go from A to B, and then from B to C.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

DGM
DGM am 28 Nov. 2021
Bearbeitet: DGM am 28 Nov. 2021
The answer is yes, but that's not really helpful. The real question is how do you get the colormap from matplotlib into MATLAB?
The above should be a good start if you have all the python stuff already.
If it suffices to work in RGB and all you want is the one map, you can generate it from the endpoints of the sample image. This should work fine for simple 2-point RGB maps like this one.
colorA = [1 1 1]; % white
colorB = [63 0 125]/255; % sampled purple
numcolors = 16;
ct = interp1([0 1],[colorA; colorB],linspace(0,1,numcolors),'linear')
ct = 16×3
1.0000 1.0000 1.0000 0.9498 0.9333 0.9660 0.8996 0.8667 0.9320 0.8494 0.8000 0.8980 0.7992 0.7333 0.8641 0.7490 0.6667 0.8301 0.6988 0.6000 0.7961 0.6486 0.5333 0.7621 0.5984 0.4667 0.7281 0.5482 0.4000 0.6941

Kategorien

Mehr zu Orange finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by