🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colormaps.html
Choosing Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
cmaps = {} gradient = np.linspace(0, 1, 256) gradient = np.vstack((gradient, gradient)) def plot_color_gradients(category, cmap_list): # Create figure and adjust figure height to number of colormaps nrows = len(cmap_list) figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh)) fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99) axs[0].set_title(f'{category} colormaps', fontsize=14) for ax, name in zip(axs, cmap_list): ax.imshow(gradient, aspect='auto', cmap=mpl.colormaps[name]) ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10, transform=ax.transAxes) # Turn off *all* ticks & spines, not just the ones with colormaps.
🌐
GitHub
github.com › pyapp-kit › cmap
GitHub - pyapp-kit/cmap: Scientific colormaps for python, with only numpy dependency · GitHub
Scientific colormaps for python, with no dependencies beyond numpy. With cmap, you can use any of the colormaps from matplotlib, cmocean, colorbrewer, crameri, seaborn, and a host of other collections in your python code, without having to install ...
People also ask

What does cmap mean in Matplotlib?
cmap selects the colormap that maps normalized data values to colors in artists such as imshow, scatter, and contour plots.
🌐
pythonpool.com
pythonpool.com › home › matplotlib › matplotlib cmap: sequential, diverging, cyclic, and qualitative
Matplotlib cmap: Sequential, Diverging, Cyclic, and Qualitative
What is the difference between cmap and norm?
cmap chooses the colors, while norm maps data values into the interval used by the colormap.
🌐
pythonpool.com
pythonpool.com › home › matplotlib › matplotlib cmap: sequential, diverging, cyclic, and qualitative
Matplotlib cmap: Sequential, Diverging, Cyclic, and Qualitative
Which Matplotlib colormap should I use?
Use sequential for ordered magnitude, diverging for a meaningful midpoint, cyclic for wraparound values, and qualitative for unordered categories.
🌐
pythonpool.com
pythonpool.com › home › matplotlib › matplotlib cmap: sequential, diverging, cyclic, and qualitative
Matplotlib cmap: Sequential, Diverging, Cyclic, and Qualitative
🌐
Readthedocs
cmap-docs.readthedocs.io
cmap
cmap is a colormap library for python, providing all of the colormaps in matplotlib, vispy, cmocean, (and more), with no dependencies beyond numpy.
🌐
Python Pool
pythonpool.com › home › matplotlib › matplotlib cmap: sequential, diverging, cyclic, and qualitative
Matplotlib cmap: Sequential, Diverging, Cyclic, and Qualitative
July 13, 2026 - Quick answer: Choose a Matplotlib colormap by data meaning: sequential for ordered magnitude, diverging for a meaningful midpoint, cyclic for wraparound quantities, and qualitative for categories. Pair cmap with explicit normalization and a colorbar.
🌐
Colormaps
pratiman-91.github.io › colormaps
Home - Colormaps
import matplotlib.pyplot as plt import colormaps as cmaps import numpy as np x = y = np.arange(-3.0, 3.01, 0.05) X, Y = np.meshgrid(x, y) sigmax = sigmay = 1.0 mux = muy = sigmaxy=0.0 Xmu = X-mux Ymu = Y-muy rho = sigmaxy/(sigmax*sigmay) z = Xmu**2/sigmax**2 + Ymu**2/sigmay**2 - 2*rho*Xmu*Ymu/(sigmax*sigmay) denom = 2*np.pi*sigmax*sigmay*np.sqrt(1-rho**2) Z = np.exp(-z/(2*(1-rho**2))) / denom plt.pcolormesh(X,Y,Z,cmap=cmaps.cubehelix3_16_r) plt.colorbar()
🌐
GeeksforGeeks
geeksforgeeks.org › python › matplotlib-pyplot-set_cmap-in-python
Matplotlib.pyplot.set_cmap() in Python - GeeksforGeeks
July 12, 2025 - Matplotlib.pyplot.set_cmap() is a function in matplotlib that is used to set the default colormap for the current image or plot.
🌐
Seaborn
deeplearningnerds.com › matplotlib-color-maps
Matplotlib - Colormaps
December 15, 2023 - The cmap parameter is the Colormap. Here we can choose the name of a Colormap provided by Matplotlib.
Find elsewhere
🌐
Kanaries
docs.kanaries.net › topics › Matplotlib › examples-matplotlib-cmaps
Matplotlib Colormaps: Interactive Explorer and Complete Gallery – Kanaries
August 19, 2026 - How State Funding Model Affects ... Tracking UFO Sightings in U.S. ... A colormap (cmap) is the lookup table Matplotlib uses to turn numbers into colors....
🌐
PyPI
pypi.org › project › cmap
cmap
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Python Graph Gallery
python-graph-gallery.com › the python graph gallery › colors › create and customise palettes in matplotlib
Create and customise palettes in Matplotlib
1 week ago - from matplotlib.colors import ListedColormap # Define your custom color palette custom_colors = ['#264653', '#2a9d8f', '#e9c46a', '#f4a261', '#e76f51'] # Create a ListedColormap custom_cmap = ListedColormap(custom_colors) custom_cmap
🌐
Pythoncharts
pythoncharts.com › matplotlib › matplotlib-colors-colormaps
Python Charts - Colors and Color Maps in Matplotlib
import matplotlib as mpl from matplotlib import pyplot as plt import numpy as np cmaps = {} gradient = np.linspace(0, 1, 256) gradient = np.vstack((gradient, gradient)) def plot_color_gradients(category, cmap_list): # Create figure and adjust figure height to number of colormaps nrows = len(cmap_list) figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh)) fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99) axs[0].set_title(f'{category} colormaps', fontsize=14) for ax, name in zip(axs, cmap_list): ax.imshow(gradient, aspect='auto', cmap=mpl.colormaps[name]) ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10, transform=ax.transAxes) # Turn off *all* ticks & spines, not just the ones with colormaps.
🌐
GitHub
github.com › hhuangwx › cmaps
GitHub - hhuangwx/cmaps: user defined colormaps in matplotlib. · GitHub
a cmap can now be interpolated (different from the "resampled" function in the new version of matplotlib which only takes the nearest ones):
Top answer
1 of 9
415

You can do this with the code below, and the code in your question was actually very close to what you needed, all you have to do is call the cmap object you have.

import matplotlib

cmap = matplotlib.cm.get_cmap('Spectral')

rgba = cmap(0.5)
print(rgba) # (0.99807766255210428, 0.99923106502084169, 0.74602077638401709, 1.0)

For values outside of the range [0.0, 1.0] it will return the under and over colour (respectively). This, by default, is the minimum and maximum colour within the range (so 0.0 and 1.0). This default can be changed with cmap.set_under() and cmap.set_over().

For "special" numbers such as np.nan and np.inf the default is to use the 0.0 value, this can be changed using cmap.set_bad() similarly to under and over as above.

Finally it may be necessary for you to normalize your data such that it conforms to the range [0.0, 1.0]. This can be done using matplotlib.colors.Normalize simply as shown in the small example below where the arguments vmin and vmax describe what numbers should be mapped to 0.0 and 1.0 respectively.

import matplotlib

norm = matplotlib.colors.Normalize(vmin=10.0, vmax=20.0)

print(norm(15.0)) # 0.5

A logarithmic normaliser (matplotlib.colors.LogNorm) is also available for data ranges with a large range of values.

(Thanks to both Joe Kington and tcaswell for suggestions on how to improve the answer.)

2 of 9
24

In order to get rgba integer value instead of float value, we can do

rgba = cmap(0.5,bytes=True)

So to simplify the code based on answer from Ffisegydd, the code would be like this:

#import colormap
from matplotlib import cm

#normalize item number values to colormap
norm = matplotlib.colors.Normalize(vmin=0, vmax=1000)

#colormap possible values = viridis, jet, spectral
rgba_color = cm.jet(norm(400),bytes=True) 

#400 is one of value between 0 and 1000
🌐
LabEx
labex.io › questions › what-is-cmap-660161
What is cmap? | LabEx
August 6, 2025 - In programming, particularly in data visualization libraries like Matplotlib (Python), `cmap` refers to "colormap.
🌐
Readthedocs
colormap.readthedocs.io
COLORMAP documentation — colormap 1.3.0 documentation
from colormap import Colormap c = Colormap() mycmap = c.cmap( {'red':[1,1,0], 'green':[0,1,.39], 'blue':[0,1,0]}) cmap = c.test_colormap(mycmap)
Top answer
1 of 4
138

Since the methods used in other answers seems quite complicated for such easy task, here is a new answer:

Instead of a ListedColormap, which produces a discrete colormap, you may use a LinearSegmentedColormap. This can easily be created from a list using the from_list method.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors

x,y,c = zip(*np.random.rand(30,3)*4-2)

norm=plt.Normalize(-2,2)
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","violet","blue"])

plt.scatter(x,y,c=c, cmap=cmap, norm=norm)
plt.colorbar()
plt.show()


More generally, if you have a list of values (e.g. [-2., -1, 2]) and corresponding colors, (e.g. ["red","violet","blue"]), such that the nth value should correspond to the nth color, you can normalize the values and supply them as tuples to the from_list method.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors

x,y,c = zip(*np.random.rand(30,3)*4-2)

cvals  = [-2., -1, 2]
colors = ["red","violet","blue"]

norm=plt.Normalize(min(cvals),max(cvals))
tuples = list(zip(map(norm,cvals), colors))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)

plt.scatter(x,y,c=c, cmap=cmap, norm=norm)
plt.colorbar()
plt.show()

2 of 4
96

There is an illustrative example of how to create custom colormaps here. The docstring is essential for understanding the meaning of cdict. Once you get that under your belt, you might use a cdict like this:

cdict = {'red':   ((0.0, 1.0, 1.0), 
                   (0.1, 1.0, 1.0),  # red 
                   (0.4, 1.0, 1.0),  # violet
                   (1.0, 0.0, 0.0)), # blue

         'green': ((0.0, 0.0, 0.0),
                   (1.0, 0.0, 0.0)),

         'blue':  ((0.0, 0.0, 0.0),
                   (0.1, 0.0, 0.0),  # red
                   (0.4, 1.0, 1.0),  # violet
                   (1.0, 1.0, 0.0))  # blue
          }

Although the cdict format gives you a lot of flexibility, I find for simple gradients its format is rather unintuitive. Here is a utility function to help generate simple LinearSegmentedColormaps:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors


def make_colormap(seq):
    """Return a LinearSegmentedColormap
    seq: a sequence of floats and RGB-tuples. The floats should be increasing
    and in the interval (0,1).
    """
    seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
    cdict = {'red': [], 'green': [], 'blue': []}
    for i, item in enumerate(seq):
        if isinstance(item, float):
            r1, g1, b1 = seq[i - 1]
            r2, g2, b2 = seq[i + 1]
            cdict['red'].append([item, r1, r2])
            cdict['green'].append([item, g1, g2])
            cdict['blue'].append([item, b1, b2])
    return mcolors.LinearSegmentedColormap('CustomMap', cdict)


c = mcolors.ColorConverter().to_rgb
rvb = make_colormap(
    [c('red'), c('violet'), 0.33, c('violet'), c('blue'), 0.66, c('blue')])
N = 1000
array_dg = np.random.uniform(0, 10, size=(N, 2))
colors = np.random.uniform(-2, 2, size=(N,))
plt.scatter(array_dg[:, 0], array_dg[:, 1], c=colors, cmap=rvb)
plt.colorbar()
plt.show()


By the way, the for-loop

for i in range(0, len(array_dg)):
  plt.plot(array_dg[i], markers.next(),alpha=alpha[i], c=colors.next())

plots one point for every call to plt.plot. This will work for a small number of points, but will become extremely slow for many points. plt.plot can only draw in one color, but plt.scatter can assign a different color to each dot. Thus, plt.scatter is the way to go.

🌐
GeeksforGeeks
geeksforgeeks.org › python › matplotlib-colors-colormap-class-in-python
Matplotlib Colormaps - GeeksforGeeks
December 23, 2024 - Python · import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LinearSegmentedColormap colors = ["blue", "green", "yellow"] cmap = LinearSegmentedColormap.from_list("CustomCmap", colors) data = np.random.randn(10, 10) plt.imshow(data, cmap=cmap) plt.colorbar() plt.show() Output: LinearSegmentedColormap ·
🌐
Matplotlib
matplotlib.org › stable › gallery › color › colormap_reference.html
Colormap reference — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np cmaps = [('Perceptually Uniform Sequential', [ 'viridis', 'plasma', 'inferno', 'magma', 'cividis']), ('Sequential', [ 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']), ('Sequential (2)', [ 'gray', 'bone', 'pink', 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper']), ('Diverging', [ 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismi