Is it possible to use the colormap "Purples" in MATLAB, which maps zeros to white?
24 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
John D'Errico
on 28 Nov 2021
Edited: John D'Errico
on 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 Comments
John D'Errico
on 28 Nov 2021
Edited: John D'Errico
on 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.
More Answers (1)
DGM
on 28 Nov 2021
Edited: DGM
on 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')
0 Comments
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!