> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Full List of Named Colors in Pandas and Python
- URL: https://datascientyst.com/full-list-named-colors-pandas-python-matplotlib/
- Published: 2022-02-02T22:11:46.000Z
- Updated: 2023-03-31T06:59:33.000Z
- Author: John D K
- Tags: Basic concepts 420

## 1\. Overview

This article is a reference of all named colors in Pandas. It **shows a list of more than 1200+ named colors in Python, Matplotlib and Pandas.** They are based on the Python library Matplotlib.

The work in based on two articles:

- [How to Get a List of N Different Colors and Names in Python/Pandas ](https://datascientyst.com/get-list-of-n-different-colors-names-python-pandas/)
- [List of named colors - Matplotlib](https://matplotlib.org/stable/gallery/color/named%5Fcolors.html?ref=datascientyst.com)

We are going to build different color palettes and different conversion techniques.

The image below shows some of the colors:

![full-list-named-colors-pandas-python-matplotlib](https://datascientyst.com/content/images/2022/10/full-list-named-colors-pandas-python-matplotlib.webp)

## 2\. Convert colors in Matplotlib, Python and Pandas

To learn more about the color conversion in Python you can check 5th step of the above article: [Working with color names and color values](https://datascientyst.com/get-list-of-n-different-colors-names-python-pandas/#step-5-working-with-color-names-and-color-values-format-html-and-css-in-python)

In this section we will cover the next conversions:

- RGB to HEX = `(0.0, 1.0, 1.0)` \-> `#00FFFF`
- HEX to RGB = `#00FFFF` \-> `(0.0, 1.0, 1.0)`

### 2.1\. Convert RGB to HEX color in Python and Pandas

Let's start with conversion of RGB color in decimal code to HEX code. To do so we are going to use Matplotlib method: `mcolors.rgb2hex()`:

```python
import matplotlib.colors as mcolors
mcolors.rgb2hex((0.0, 1.0, 1.0))

```

result:

```
'#00ffff'

```

### 2.2\. Convert RGB to HSL in Pandas

To convert from RGB to HSL in Pandas we are going to use method: `rgb_to_hsv`:

```python
mcolors.rgb_to_hsv((0, 0, 1))

```

the output is array of hue, saturation and lightness:

```
array([0.66666667, 1.        , 1.        ])

```

### 2.3\. Convert HEX to RGB format in Python and Pandas

Similarly we can do the HEX to RGB conversion by using method - \`mcolors.hex2color():

```python
import matplotlib.colors as mcolors
mcolors.hex2color('#40E0D0')

```

result:

```
(0.25098039215686274, 0.8784313725490196, 0.8156862745098039)

```

The result has high decimal precision. If you like to reduce the decimal numbers we can use list comprehension:

```python
[round(c, 5) for c in (0.25098039215686274, 0.8784313725490196, 0.8156862745098039)]

```

will give us:

```
[0.25098, 0.87843, 0.81569]

```

To apply to a column in Pandas DataFrame we can use a lambda expression:

```python
df_colors['rgb'] = df_colors['rgb'].apply(lambda x:[round(c, 5) for c in x])

```

### 2.4\. Convert RGB to HEX color for whole column in Pandas

We can also apply the conversion to a single or multiple columns in Pandas DataFrame. For this purpose we are going to use method `apply()`:

```python
df_colors['hex'] = df_colors['rgb'].apply(mcolors.rgb2hex)

```

The following example demonstrate this:

```python
import pandas as pd
colors = {
    'name': mcolors.BASE_COLORS.keys(),
    'rgb': mcolors.BASE_COLORS.values()
    
}

df_colors = pd.DataFrame(colors)
df_colors['hex'] = df_colors['rgb'].apply(mcolors.rgb2hex)

```

The result DataFrame with converted RGB column to HEX one:

|   | name | rgb             | hex     |
| - | ---- | --------------- | ------- |
| 0 | b    | (0, 0, 1)       | #0000ff |
| 1 | g    | (0, 0.5, 0)     | #008000 |
| 2 | r    | (1, 0, 0)       | #ff0000 |
| 3 | c    | (0, 0.75, 0.75) | #00bfbf |
| 4 | m    | (0.75, 0, 0.75) | #bf00bf |

## 3\. BASE\_COLORS: Named Colors in Pandas

We will start with the most basic colors with names from Matplotlib - `mcolors.BASE_COLORS`.

Below you can find a table with the color name, RGB and HEX values plus display of the color:

We are going to use the next code to generate the values:

```python
import pandas as pd

def format_color_groups(df, color):
    x = df.copy()
    i = 0
    
    
    for factor in color:
        x.iloc[i, :-1] = ''    
        style = f'background-color: {color[i]}'
        x.loc[i, 'display color as background'] = style
        i = i + 1
            
        
    return x

colors = {
    'name': mcolors.BASE_COLORS.keys(),
    'rgb': mcolors.BASE_COLORS.values()
    
}

df_colors = pd.DataFrame(colors)
df_colors['hex'] = df_colors['rgb'].apply(mcolors.rgb2hex)

df_colors['display color as background'] = ''
df_colors.style.apply(format_color_groups, color=df_colors.hex,  axis=None)

```

The list of the basic colors in Pandas is shown below:

|   | name | rgb             | hex     | display color as background |
| - | ---- | --------------- | ------- | --------------------------- |
| 0 | b    | (0, 0, 1)       | #0000ff |                             |
| 1 | g    | (0, 0.5, 0)     | #008000 |                             |
| 2 | r    | (1, 0, 0)       | #ff0000 |                             |
| 3 | c    | (0, 0.75, 0.75) | #00bfbf |                             |
| 4 | m    | (0.75, 0, 0.75) | #bf00bf |                             |
| 5 | y    | (0.75, 0.75, 0) | #bfbf00 |                             |
| 6 | k    | (0, 0, 0)       | #000000 |                             |
| 7 | w    | (1, 1, 1)       | #ffffff |                             |

## 4\. TABLEAU\_COLORS: List of Named Colors in Python and Pandas

Next we will cover the list of TABLEAU\_COLORS in Pandas. They are limited to the most popular colors only. The code below will list all of them:

```python
import pandas as pd

def format_color_groups(df, color):
    x = df.copy()
    i = 0
    
    
    for factor in color:
        x.iloc[i, :-1] = ''    
        style = f'background-color: {color[i]}'
        x.loc[i, 'display color as background'] = style
        i = i + 1
            
        
    return x

colors = {
    'name': mcolors.TABLEAU_COLORS.keys(),
    'hex': mcolors.TABLEAU_COLORS.values()
    
}

df_colors = pd.DataFrame(colors)
df_colors['rgb'] = df_colors['hex'].apply(mcolors.hex2color)

df_colors['rgb'] = df_colors['rgb'].apply(lambda x:[round(c, 5) for c in x])

df_colors['display color as background'] = ''
df_colors.style.apply(format_color_groups, color=df_colors.hex,  axis=None)

```

And the table is:

|   | name       | hex     | rgb                           | display color as background |
| - | ---------- | ------- | ----------------------------- | --------------------------- |
| 0 | tab:blue   | #1f77b4 | \[0.12157, 0.46667, 0.70588\] |                             |
| 1 | tab:orange | #ff7f0e | \[1.0, 0.49804, 0.0549\]      |                             |
| 2 | tab:green  | #2ca02c | \[0.17255, 0.62745, 0.17255\] |                             |
| 3 | tab:red    | #d62728 | \[0.83922, 0.15294, 0.15686\] |                             |
| 4 | tab:purple | #9467bd | \[0.58039, 0.40392, 0.74118\] |                             |
| 5 | tab:brown  | #8c564b | \[0.54902, 0.33725, 0.29412\] |                             |
| 6 | tab:pink   | #e377c2 | \[0.8902, 0.46667, 0.76078\]  |                             |
| 7 | tab:gray   | #7f7f7f | \[0.49804, 0.49804, 0.49804\] |                             |
| 8 | tab:olive  | #bcbd22 | \[0.73725, 0.74118, 0.13333\] |                             |
| 9 | tab:cyan   | #17becf | \[0.0902, 0.7451, 0.81176\]   |                             |

## 5\. CSS4\_COLORS colors in Python and Pandas

The CSS4\_COLORS contains many different named colors which can be used in Python and Matplotlib. We can list all of them by:

```python
def format_color_groups(df, color):
    x = df.copy()
    i = 0
    
    
    for factor in color:
        x.iloc[i, :-1] = ''    
        style = f'background-color: {color[i]}'
        x.loc[i, 'display color as background'] = style
        i = i + 1
            
        
    return x

colors = {
    'name': mcolors.CSS4_COLORS.keys(),
    'hex': mcolors.CSS4_COLORS.values()
    
}

df_colors = pd.DataFrame(colors)
df_colors['rgb'] = df_colors['hex'].apply(mcolors.hex2color)

df_colors['rgb'] = df_colors['rgb'].apply(lambda x:[round(c, 5) for c in x])

df_colors['display color as background'] = ''
df_colors.style.apply(format_color_groups, color=df_colors.hex,  axis=None)

```

We can find all the colors from this pallet below:

|     | name                 | hex     | rgb                           | display color as background |
| --- | -------------------- | ------- | ----------------------------- | --------------------------- |
| 0   | aliceblue            | #F0F8FF | \[0.94118, 0.97255, 1.0\]     |                             |
| 1   | antiquewhite         | #FAEBD7 | \[0.98039, 0.92157, 0.84314\] |                             |
| 2   | aqua                 | #00FFFF | \[0.0, 1.0, 1.0\]             |                             |
| 3   | aquamarine           | #7FFFD4 | \[0.49804, 1.0, 0.83137\]     |                             |
| 4   | azure                | #F0FFFF | \[0.94118, 1.0, 1.0\]         |                             |
| 5   | beige                | #F5F5DC | \[0.96078, 0.96078, 0.86275\] |                             |
| 6   | bisque               | #FFE4C4 | \[1.0, 0.89412, 0.76863\]     |                             |
| 7   | black                | #000000 | \[0.0, 0.0, 0.0\]             |                             |
| 8   | blanchedalmond       | #FFEBCD | \[1.0, 0.92157, 0.80392\]     |                             |
| 9   | blue                 | #0000FF | \[0.0, 0.0, 1.0\]             |                             |
| 10  | blueviolet           | #8A2BE2 | \[0.54118, 0.16863, 0.88627\] |                             |
| 11  | brown                | #A52A2A | \[0.64706, 0.16471, 0.16471\] |                             |
| 12  | burlywood            | #DEB887 | \[0.87059, 0.72157, 0.52941\] |                             |
| 13  | cadetblue            | #5F9EA0 | \[0.37255, 0.61961, 0.62745\] |                             |
| 14  | chartreuse           | #7FFF00 | \[0.49804, 1.0, 0.0\]         |                             |
| 15  | chocolate            | #D2691E | \[0.82353, 0.41176, 0.11765\] |                             |
| 16  | coral                | #FF7F50 | \[1.0, 0.49804, 0.31373\]     |                             |
| 17  | cornflowerblue       | #6495ED | \[0.39216, 0.58431, 0.92941\] |                             |
| 18  | cornsilk             | #FFF8DC | \[1.0, 0.97255, 0.86275\]     |                             |
| 19  | crimson              | #DC143C | \[0.86275, 0.07843, 0.23529\] |                             |
| 20  | cyan                 | #00FFFF | \[0.0, 1.0, 1.0\]             |                             |
| 21  | darkblue             | #00008B | \[0.0, 0.0, 0.5451\]          |                             |
| 22  | darkcyan             | #008B8B | \[0.0, 0.5451, 0.5451\]       |                             |
| 23  | darkgoldenrod        | #B8860B | \[0.72157, 0.52549, 0.04314\] |                             |
| 24  | darkgray             | #A9A9A9 | \[0.66275, 0.66275, 0.66275\] |                             |
| 25  | darkgreen            | #006400 | \[0.0, 0.39216, 0.0\]         |                             |
| 26  | darkgrey             | #A9A9A9 | \[0.66275, 0.66275, 0.66275\] |                             |
| 27  | darkkhaki            | #BDB76B | \[0.74118, 0.71765, 0.41961\] |                             |
| 28  | darkmagenta          | #8B008B | \[0.5451, 0.0, 0.5451\]       |                             |
| 29  | darkolivegreen       | #556B2F | \[0.33333, 0.41961, 0.18431\] |                             |
| 30  | darkorange           | #FF8C00 | \[1.0, 0.54902, 0.0\]         |                             |
| 31  | darkorchid           | #9932CC | \[0.6, 0.19608, 0.8\]         |                             |
| 32  | darkred              | #8B0000 | \[0.5451, 0.0, 0.0\]          |                             |
| 33  | darksalmon           | #E9967A | \[0.91373, 0.58824, 0.47843\] |                             |
| 34  | darkseagreen         | #8FBC8F | \[0.56078, 0.73725, 0.56078\] |                             |
| 35  | darkslateblue        | #483D8B | \[0.28235, 0.23922, 0.5451\]  |                             |
| 36  | darkslategray        | #2F4F4F | \[0.18431, 0.3098, 0.3098\]   |                             |
| 37  | darkslategrey        | #2F4F4F | \[0.18431, 0.3098, 0.3098\]   |                             |
| 38  | darkturquoise        | #00CED1 | \[0.0, 0.80784, 0.81961\]     |                             |
| 39  | darkviolet           | #9400D3 | \[0.58039, 0.0, 0.82745\]     |                             |
| 40  | deeppink             | #FF1493 | \[1.0, 0.07843, 0.57647\]     |                             |
| 41  | deepskyblue          | #00BFFF | \[0.0, 0.74902, 1.0\]         |                             |
| 42  | dimgray              | #696969 | \[0.41176, 0.41176, 0.41176\] |                             |
| 43  | dimgrey              | #696969 | \[0.41176, 0.41176, 0.41176\] |                             |
| 44  | dodgerblue           | #1E90FF | \[0.11765, 0.56471, 1.0\]     |                             |
| 45  | firebrick            | #B22222 | \[0.69804, 0.13333, 0.13333\] |                             |
| 46  | floralwhite          | #FFFAF0 | \[1.0, 0.98039, 0.94118\]     |                             |
| 47  | forestgreen          | #228B22 | \[0.13333, 0.5451, 0.13333\]  |                             |
| 48  | fuchsia              | #FF00FF | \[1.0, 0.0, 1.0\]             |                             |
| 49  | gainsboro            | #DCDCDC | \[0.86275, 0.86275, 0.86275\] |                             |
| 50  | ghostwhite           | #F8F8FF | \[0.97255, 0.97255, 1.0\]     |                             |
| 51  | gold                 | #FFD700 | \[1.0, 0.84314, 0.0\]         |                             |
| 52  | goldenrod            | #DAA520 | \[0.8549, 0.64706, 0.12549\]  |                             |
| 53  | gray                 | #808080 | \[0.50196, 0.50196, 0.50196\] |                             |
| 54  | green                | #008000 | \[0.0, 0.50196, 0.0\]         |                             |
| 55  | greenyellow          | #ADFF2F | \[0.67843, 1.0, 0.18431\]     |                             |
| 56  | grey                 | #808080 | \[0.50196, 0.50196, 0.50196\] |                             |
| 57  | honeydew             | #F0FFF0 | \[0.94118, 1.0, 0.94118\]     |                             |
| 58  | hotpink              | #FF69B4 | \[1.0, 0.41176, 0.70588\]     |                             |
| 59  | indianred            | #CD5C5C | \[0.80392, 0.36078, 0.36078\] |                             |
| 60  | indigo               | #4B0082 | \[0.29412, 0.0, 0.5098\]      |                             |
| 61  | ivory                | #FFFFF0 | \[1.0, 1.0, 0.94118\]         |                             |
| 62  | khaki                | #F0E68C | \[0.94118, 0.90196, 0.54902\] |                             |
| 63  | lavender             | #E6E6FA | \[0.90196, 0.90196, 0.98039\] |                             |
| 64  | lavenderblush        | #FFF0F5 | \[1.0, 0.94118, 0.96078\]     |                             |
| 65  | lawngreen            | #7CFC00 | \[0.48627, 0.98824, 0.0\]     |                             |
| 66  | lemonchiffon         | #FFFACD | \[1.0, 0.98039, 0.80392\]     |                             |
| 67  | lightblue            | #ADD8E6 | \[0.67843, 0.84706, 0.90196\] |                             |
| 68  | lightcoral           | #F08080 | \[0.94118, 0.50196, 0.50196\] |                             |
| 69  | lightcyan            | #E0FFFF | \[0.87843, 1.0, 1.0\]         |                             |
| 70  | lightgoldenrodyellow | #FAFAD2 | \[0.98039, 0.98039, 0.82353\] |                             |
| 71  | lightgray            | #D3D3D3 | \[0.82745, 0.82745, 0.82745\] |                             |
| 72  | lightgreen           | #90EE90 | \[0.56471, 0.93333, 0.56471\] |                             |
| 73  | lightgrey            | #D3D3D3 | \[0.82745, 0.82745, 0.82745\] |                             |
| 74  | lightpink            | #FFB6C1 | \[1.0, 0.71373, 0.75686\]     |                             |
| 75  | lightsalmon          | #FFA07A | \[1.0, 0.62745, 0.47843\]     |                             |
| 76  | lightseagreen        | #20B2AA | \[0.12549, 0.69804, 0.66667\] |                             |
| 77  | lightskyblue         | #87CEFA | \[0.52941, 0.80784, 0.98039\] |                             |
| 78  | lightslategray       | #778899 | \[0.46667, 0.53333, 0.6\]     |                             |
| 79  | lightslategrey       | #778899 | \[0.46667, 0.53333, 0.6\]     |                             |
| 80  | lightsteelblue       | #B0C4DE | \[0.6902, 0.76863, 0.87059\]  |                             |
| 81  | lightyellow          | #FFFFE0 | \[1.0, 1.0, 0.87843\]         |                             |
| 82  | lime                 | #00FF00 | \[0.0, 1.0, 0.0\]             |                             |
| 83  | limegreen            | #32CD32 | \[0.19608, 0.80392, 0.19608\] |                             |
| 84  | linen                | #FAF0E6 | \[0.98039, 0.94118, 0.90196\] |                             |
| 85  | magenta              | #FF00FF | \[1.0, 0.0, 1.0\]             |                             |
| 86  | maroon               | #800000 | \[0.50196, 0.0, 0.0\]         |                             |
| 87  | mediumaquamarine     | #66CDAA | \[0.4, 0.80392, 0.66667\]     |                             |
| 88  | mediumblue           | #0000CD | \[0.0, 0.0, 0.80392\]         |                             |
| 89  | mediumorchid         | #BA55D3 | \[0.72941, 0.33333, 0.82745\] |                             |
| 90  | mediumpurple         | #9370DB | \[0.57647, 0.43922, 0.85882\] |                             |
| 91  | mediumseagreen       | #3CB371 | \[0.23529, 0.70196, 0.44314\] |                             |
| 92  | mediumslateblue      | #7B68EE | \[0.48235, 0.40784, 0.93333\] |                             |
| 93  | mediumspringgreen    | #00FA9A | \[0.0, 0.98039, 0.60392\]     |                             |
| 94  | mediumturquoise      | #48D1CC | \[0.28235, 0.81961, 0.8\]     |                             |
| 95  | mediumvioletred      | #C71585 | \[0.78039, 0.08235, 0.52157\] |                             |
| 96  | midnightblue         | #191970 | \[0.09804, 0.09804, 0.43922\] |                             |
| 97  | mintcream            | #F5FFFA | \[0.96078, 1.0, 0.98039\]     |                             |
| 98  | mistyrose            | #FFE4E1 | \[1.0, 0.89412, 0.88235\]     |                             |
| 99  | moccasin             | #FFE4B5 | \[1.0, 0.89412, 0.7098\]      |                             |
| 100 | navajowhite          | #FFDEAD | \[1.0, 0.87059, 0.67843\]     |                             |
| 101 | navy                 | #000080 | \[0.0, 0.0, 0.50196\]         |                             |
| 102 | oldlace              | #FDF5E6 | \[0.99216, 0.96078, 0.90196\] |                             |
| 103 | olive                | #808000 | \[0.50196, 0.50196, 0.0\]     |                             |
| 104 | olivedrab            | #6B8E23 | \[0.41961, 0.55686, 0.13725\] |                             |
| 105 | orange               | #FFA500 | \[1.0, 0.64706, 0.0\]         |                             |
| 106 | orangered            | #FF4500 | \[1.0, 0.27059, 0.0\]         |                             |
| 107 | orchid               | #DA70D6 | \[0.8549, 0.43922, 0.83922\]  |                             |
| 108 | palegoldenrod        | #EEE8AA | \[0.93333, 0.9098, 0.66667\]  |                             |
| 109 | palegreen            | #98FB98 | \[0.59608, 0.98431, 0.59608\] |                             |
| 110 | paleturquoise        | #AFEEEE | \[0.68627, 0.93333, 0.93333\] |                             |
| 111 | palevioletred        | #DB7093 | \[0.85882, 0.43922, 0.57647\] |                             |
| 112 | papayawhip           | #FFEFD5 | \[1.0, 0.93725, 0.83529\]     |                             |
| 113 | peachpuff            | #FFDAB9 | \[1.0, 0.8549, 0.72549\]      |                             |
| 114 | peru                 | #CD853F | \[0.80392, 0.52157, 0.24706\] |                             |
| 115 | pink                 | #FFC0CB | \[1.0, 0.75294, 0.79608\]     |                             |
| 116 | plum                 | #DDA0DD | \[0.86667, 0.62745, 0.86667\] |                             |
| 117 | powderblue           | #B0E0E6 | \[0.6902, 0.87843, 0.90196\]  |                             |
| 118 | purple               | #800080 | \[0.50196, 0.0, 0.50196\]     |                             |
| 119 | rebeccapurple        | #663399 | \[0.4, 0.2, 0.6\]             |                             |
| 120 | red                  | #FF0000 | \[1.0, 0.0, 0.0\]             |                             |
| 121 | rosybrown            | #BC8F8F | \[0.73725, 0.56078, 0.56078\] |                             |
| 122 | royalblue            | #4169E1 | \[0.2549, 0.41176, 0.88235\]  |                             |
| 123 | saddlebrown          | #8B4513 | \[0.5451, 0.27059, 0.07451\]  |                             |
| 124 | salmon               | #FA8072 | \[0.98039, 0.50196, 0.44706\] |                             |
| 125 | sandybrown           | #F4A460 | \[0.95686, 0.64314, 0.37647\] |                             |
| 126 | seagreen             | #2E8B57 | \[0.18039, 0.5451, 0.34118\]  |                             |
| 127 | seashell             | #FFF5EE | \[1.0, 0.96078, 0.93333\]     |                             |
| 128 | sienna               | #A0522D | \[0.62745, 0.32157, 0.17647\] |                             |
| 129 | silver               | #C0C0C0 | \[0.75294, 0.75294, 0.75294\] |                             |
| 130 | skyblue              | #87CEEB | \[0.52941, 0.80784, 0.92157\] |                             |
| 131 | slateblue            | #6A5ACD | \[0.41569, 0.35294, 0.80392\] |                             |
| 132 | slategray            | #708090 | \[0.43922, 0.50196, 0.56471\] |                             |
| 133 | slategrey            | #708090 | \[0.43922, 0.50196, 0.56471\] |                             |
| 134 | snow                 | #FFFAFA | \[1.0, 0.98039, 0.98039\]     |                             |
| 135 | springgreen          | #00FF7F | \[0.0, 1.0, 0.49804\]         |                             |
| 136 | steelblue            | #4682B4 | \[0.27451, 0.5098, 0.70588\]  |                             |
| 137 | tan                  | #D2B48C | \[0.82353, 0.70588, 0.54902\] |                             |
| 138 | teal                 | #008080 | \[0.0, 0.50196, 0.50196\]     |                             |
| 139 | thistle              | #D8BFD8 | \[0.84706, 0.74902, 0.84706\] |                             |
| 140 | tomato               | #FF6347 | \[1.0, 0.38824, 0.27843\]     |                             |
| 141 | turquoise            | #40E0D0 | \[0.25098, 0.87843, 0.81569\] |                             |
| 142 | violet               | #EE82EE | \[0.93333, 0.5098, 0.93333\]  |                             |
| 143 | wheat                | #F5DEB3 | \[0.96078, 0.87059, 0.70196\] |                             |
| 144 | white                | #FFFFFF | \[1.0, 1.0, 1.0\]             |                             |
| 145 | whitesmoke           | #F5F5F5 | \[0.96078, 0.96078, 0.96078\] |                             |
| 146 | yellow               | #FFFF00 | \[1.0, 1.0, 0.0\]             |                             |
| 147 | yellowgreen          | #9ACD32 | \[0.60392, 0.80392, 0.19608\] |                             |

## 6\. XKCD\_Colors: colors in Pandas and Python

Finally we will cover huge list of named colors in Python: XKCD\_Colors. The list contains about 950 colors. So we are going to list only some of them:

The code for listing all 900+ XKCD\_Colors in Pandas is similar to the previous ones:

```python
def format_color_groups(df, color):
    x = df.copy()
    i = 0
    
    
    for factor in color:
        x.iloc[i, :-1] = ''    
        style = f'background-color: {color[i]}'
        x.loc[i, 'display color as background'] = style
        i = i + 1
            
        
    return x

colors = {
    'name': mcolors.XKCD_COLORS.keys(),
    'hex': mcolors.XKCD_COLORS.values()
    
}

df_colors = pd.DataFrame(colors)
df_colors['rgb'] = df_colors['hex'].apply(mcolors.hex2color)

df_colors['rgb'] = df_colors['rgb'].apply(lambda x:[round(c, 5) for c in x])

df_colors['display color as background'] = ''
df_colors.style.apply(format_color_groups, color=df_colors.hex,  axis=None)

```

Sample of the first 15 colors:

|    | name                   | hex     | rgb                           | display color as background |
| -- | ---------------------- | ------- | ----------------------------- | --------------------------- |
| 0  | xkcd:cloudy blue       | #acc2d9 | \[0.67451, 0.76078, 0.85098\] |                             |
| 1  | xkcd:dark pastel green | #56ae57 | \[0.33725, 0.68235, 0.34118\] |                             |
| 2  | xkcd:dust              | #b2996e | \[0.69804, 0.6, 0.43137\]     |                             |
| 3  | xkcd:electric lime     | #a8ff04 | \[0.65882, 1.0, 0.01569\]     |                             |
| 4  | xkcd:fresh green       | #69d84f | \[0.41176, 0.84706, 0.3098\]  |                             |
| 5  | xkcd:light eggplant    | #894585 | \[0.53725, 0.27059, 0.52157\] |                             |
| 6  | xkcd:nasty green       | #70b23f | \[0.43922, 0.69804, 0.24706\] |                             |
| 7  | xkcd:really light blue | #d4ffff | \[0.83137, 1.0, 1.0\]         |                             |
| 8  | xkcd:tea               | #65ab7c | \[0.39608, 0.67059, 0.48627\] |                             |
| 9  | xkcd:warm purple       | #952e8f | \[0.58431, 0.18039, 0.56078\] |                             |
| 10 | xkcd:yellowish tan     | #fcfc81 | \[0.98824, 0.98824, 0.50588\] |                             |
| 11 | xkcd:cement            | #a5a391 | \[0.64706, 0.63922, 0.56863\] |                             |
| 12 | xkcd:dark grass green  | #388004 | \[0.21961, 0.50196, 0.01569\] |                             |
| 13 | xkcd:dusty teal        | #4c9085 | \[0.29804, 0.56471, 0.52157\] |                             |
| 14 | xkcd:grey teal         | #5e9b8a | \[0.36863, 0.60784, 0.54118\] |                             |

## 7\. Matplotlib colors palettes - cmaps

In this section we can find list and view of all Matplotlib colors palettes. They are known as `cmap` and can be found in Pandas functions like parameters.

In total there are 166 Matplotlib colors palettes:

> \['magma', 'inferno', 'plasma', 'viridis', 'cividis', 'twilight', 'twilight\_shifted', 'turbo', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Spectral', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist\_earth', 'gist\_gray', 'gist\_heat', 'gist\_ncar', 'gist\_rainbow', 'gist\_stern', 'gist\_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy\_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spring', 'summer', 'terrain', 'winter', 'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c', 'magma\_r', 'inferno\_r', 'plasma\_r', 'viridis\_r', 'cividis\_r', 'twilight\_r', 'twilight\_shifted\_r', 'turbo\_r', 'Blues\_r', 'BrBG\_r', 'BuGn\_r', 'BuPu\_r', 'CMRmap\_r', 'GnBu\_r', 'Greens\_r', 'Greys\_r', 'OrRd\_r', 'Oranges\_r', 'PRGn\_r', 'PiYG\_r', 'PuBu\_r', 'PuBuGn\_r', 'PuOr\_r', 'PuRd\_r', 'Purples\_r', 'RdBu\_r', 'RdGy\_r', 'RdPu\_r', 'RdYlBu\_r', 'RdYlGn\_r', 'Reds\_r', 'Spectral\_r', 'Wistia\_r', 'YlGn\_r', 'YlGnBu\_r', 'YlOrBr\_r', 'YlOrRd\_r', 'afmhot\_r', 'autumn\_r', 'binary\_r', 'bone\_r', 'brg\_r', 'bwr\_r', 'cool\_r', 'coolwarm\_r', 'copper\_r', 'cubehelix\_r', 'flag\_r', 'gist\_earth\_r', 'gist\_gray\_r', 'gist\_heat\_r', 'gist\_ncar\_r', 'gist\_rainbow\_r', 'gist\_stern\_r', 'gist\_yarg\_r', 'gnuplot\_r', 'gnuplot2\_r', 'gray\_r', 'hot\_r', 'hsv\_r', 'jet\_r', 'nipy\_spectral\_r', 'ocean\_r', 'pink\_r', 'prism\_r', 'rainbow\_r', 'seismic\_r', 'spring\_r', 'summer\_r', 'terrain\_r', 'winter\_r', 'Accent\_r', 'Dark2\_r', 'Paired\_r', 'Pastel1\_r', 'Pastel2\_r', 'Set1\_r', 'Set2\_r', 'Set3\_r', 'tab10\_r', 'tab20\_r', 'tab20b\_r', 'tab20c\_r'\]

The image below show the palette name and the colors:

![matplotlib-colors](https://datascientyst.com/content/images/2022/11/matplotlib-colors.webp)

The code to generate this image can be found on this link: [How to view all colormaps available in matplotlib?](https://stackoverflow.com/a/68317686?ref=datascientyst.com)

## 8\. Conclusion

We saw how to list huge amount of named colors in Python and Matplotlib. We saw also how to use named colors in Pandas.

Finally we learned how to convert different color formats in Python and Pandas.

Multiple examples of Matplotlib colors are shown. **This article can be used as a quick guide or reference for Matplotlib colors and Python styling.**