Colors in Matlab
RGB colors
For coding purposes colors are mostly specified in RGB-triplets. RGB stands for Red, Blue and Green. The values range from 0 to 1. As an example: the color red is given by the triple [1,0,0]. Since it is hard to know what a certain triple (e.g. [0.5, 1, 0.5]) stands for it is more easy to call them by their name.
Matlab has an build-in function for converting colornames to RGB-triplets:
>>colorname = 'red'; >>RGBtriplet = validatecolor(colorname) ans = 1.0000 0.0000 0.0000
Valid color names are: 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black' and 'white'.
Other color formats
Other ways to specify colors are:
- hsv (hue, saturation, and value) triplets:
>> color = [0.7500 1.0000 1.0000]; % hsv code for 'indigo' >> RGB = validatecolor(color) ans = 0.5000 0.0000 1.0000
- uint8 triplets:
>> color = uint8([127 0 255)]); % uint8 code for 'indigo' >> RGB = validatecolor(color) ans = 0.4980 0.0000 1.0000
- uint16 triplets:
>> color = uint16([32768 0 65535)]); % uint16 code for 'indigo' >> RGB = validatecolor(color); ans = 0.5000 0.0000 1.0000
- hexadecimals:
>> color = {'#8000FF'}; % hexadecimal code for 'indigo' >> RGB = validatecolor(color); ans = 0.4980 0.0000 1.0000
Named colors in english, dutch, german and spanish
We have created a functions for more RGB colors by their names in english, dutch, german and spanish:
- <RGBcolors> for english names
- <RGBkleuren> for dutch names
- <RGBfarben> for german names
- <RGBcolores> for spanish names
A few examples:
>>colores.AZUL_CLARO ans = 0.5000 0.5000 1.0000 >>kleuren.FELROZE ans = 1.0000 0.0000 0.5000 >>farben.BLAU ans = 0.0000 0.0000 1.0000 >>colors.LIME ans = 0.0000 1.0000 0.0000
All the named colors are:
RGB Code | Hex Code | English Name | Nederlandse Naam | Deutsche Name | Nombre en Español | Kleur |
---|---|---|---|---|---|---|
[0.00, 1.00, 0.00] | #00FF00 | Lime | Limoen | Limettengrün | Lima | |
[1.00, 0.00, 0.00] | #FF0000 | Red | Rood | Rot | Rojo | |
[0.00, 0.00, 1.00] | #0000FF | Blue | Blauw | Blau | Azul | |
[0.00, 1.00, 1.00] | #00FFFF | Cyan | Cyaan | Cyan | Cian | |
[1.00, 0.00, 1.00] | #FF00FF | Magenta | Magenta | Magenta | Magenta | |
[1.00, 1.00, 0.00] | #FFFF00 | Yellow | Geel | Gelb | Amarillo | |
[0.00, 0.00, 0.00] | #000000 | Black | Zwart | Schwarz | Negro | |
[0.50, 0.50, 0.50] | #808080 | Grey | Grijs | Grau | Gris | |
[1.00, 1.00, 1.00] | #FFFFFF | White | Wit | Weiß | Blanco | |
[0.50, 0.00, 0.00] | #800000 | Maroon | Kastanjebruin | Kastanienbraun | Granate | |
[0.00, 0.50, 0.00] | #008000 | Green | Groen | Grün | Verde | |
[0.00, 0.00, 0.50] | #000080 | Navy Blue | Marineblauw | Marineblau | Azul Marino | |
[0.00, 0.50, 0.50] | #008080 | Olive | Olijf | Olive | Oliva | |
[0.50, 0.00, 0.50] | #800080 | Purple | Paars | Lila | Morado | |
[0.50, 0.50, 0.00] | #808000 | Teal | Zeegroen | Türkis | Verde azulado | |
[0.50, 0.00, 1.00] | #8000FF | Indigo | Indigo | Indigo | Índigo | |
[0.50, 1.00, 0.00] | #80FF00 | Chartreuse | Chartreuse | Chartreuse | Chartreuse | |
[0.00, 0.50, 1.00] | #0080FF | Royal Blue | Koningsblauw | Königsblau | Azul Real | |
[1.00, 0.00, 0.50] | #FF0080 | Hot Pink | Felroze | Knallrosa | Rosa Brilliante | |
[1.00, 0.50, 0.00] | #FF8000 | Orange | Oranje | Orange | Naranja | |
[0.00, 1.00, 0.50] | #00FF80 | Spring Green | Lentegroen | Frühlingsgrün | Verde Primavera | |
[0.50, 0.50, 1.00] | #8080FF | Light Blue | Lichtblauw | Hellblau | Azul Claro | |
[0.50, 1.00, 0.50] | #80FF80 | Light Green | Lichtgroen | Hellgrün | Verde Claro | |
[1.00, 0.50, 0.50] | #FF8080 | Salmon | Zalmroze | Lachs | Salmón | |
[0.50, 1.00, 1.00] | #80FFFF | Aquamarine | Aquamarijn | Aquamarin | Aguamarina | |
[1.00, 0.50, 1.00] | #FF80FF | Orchid | Orchidee | Orchidee | Orquídea | |
[1.00, 1.00, 0.50] | #FFFF80 | Light Yellow | Lichtgeel | Hellgelb | Amarillo Claro |
Color maps
Color maps are used for plots like surface plots. Color maps are arrays with any number of columns and RGB values for every row.
There are 18 predefined color maps in Matlab with 256 colors each. These maps are accessible by <predefinedColormaps>.
- The default colormap is 'perula'.
myMap = predefinedColormaps.summer; colormap(myMap) surf(peaks); %make a surface plot with 'summer' colors.
You can view the color map by creating an instance of predefinedColormaps and call the method show:
maps = predefinedColormaps; maps.show(perula);
When you want to see the current active colormap you can use: maps.show(colormap);
You can also define you own maps
mymap = [RGBcolors.LIME;... RGBcolors.RED;... RGBcolors.BLUE]; colormap(mymap); surf(peaks);
All predefined color maps:
Name | Description |
---|---|
parula | A smooth, perceptually uniform colormap with blue-to-yellow transitions, default in MATLAB since version R2014b. |
turbo | A vibrant, perceptually uniform colormap with a wide dynamic range, transitioning from blue to red via green and yellow. |
hsv | A circular colormap representing the hue component in the HSV color space, cycling through the full range of colors. |
hot | A colormap with transitions from black to red, then yellow, and finally white, typically used for thermal or intensity data. |
cool | A simple linear colormap that transitions smoothly from cyan to magenta, often used for contrast with warm color schemes. |
spring | A pastel colormap transitioning from magenta to yellow, often used to represent seasonal or thematic data. |
summer | A light green to yellow colormap that gives a warm, sunny feel, used for representing continuous data. |
autumn | A colormap with warm tones transitioning from red to yellow, evoking the colors of autumn leaves. |
winter | A cool colormap transitioning from blue to green, commonly used to represent water or icy conditions. |
gray | A simple grayscale colormap, transitioning linearly from black to white, often used in intensity maps. |
bone | A colormap with a grayscale base, but with a slight blue tint, designed for displaying images of bones and x-rays. |
copper | A colormap transitioning from black to copper-brown, useful for visualizing data with metallic or heat-related themes. |
pink | A pastel colormap with a gradient from dark to light pink, often used for softer data visualizations. |
lines | A colormap with distinct, evenly spaced colors, designed for line plots with many different lines. |
jet | A rainbow colormap transitioning from blue to red, previously the default in MATLAB, but criticized for non-uniform perceptual changes. |
colorcube | A discrete colormap that uses a fixed set of distinct colors, typically used for categorical or label-based data. |
prism | A repeating sequence of vivid colors, often used for periodic or cyclic data. |
flag | An alternating red, white, blue, and black colormap, often used for data with binary or oscillating patterns. |