To set viridis as your colormap using set_cmap, you must register it first:
import colormaps as cmaps
plt.register_cmap(name='viridis', cmap=cmaps.viridis)
plt.set_cmap(cmaps.viridis)
img=mpimg.imread('stinkbug.png')
lum_img = np.flipud(img[:,:,0])
imgplot = plt.pcolormesh(lum_img)
Answer from aganders3 on Stack OverflowMatplotlib
matplotlib.org › 3.5.3 › api › _as_gen › matplotlib.pyplot.viridis.html
matplotlib.pyplot.viridis — Matplotlib 3.5.3 documentation
Set the colormap to 'viridis'. This changes the default colormap as well as the colormap of the current image if there is one. See help(colormaps) for more information. You are reading an old version of the documentation (v3.5.3). For the latest version see https://matplotlib.org/stable/
List of named colors
Go to the end to download the full example code · This plots a list of the named colors supported by Matplotlib. For more information on colors in matplotlib see
matplotlib.pyplot.plot
Plot y versus x as lines and/or markers · The coordinates of the points or line nodes are given by x, y
matplotlib.pyplot.legend
Place a legend on the Axes · The call signatures correspond to the following different ways to use this method:
matplotlib.pyplot.scatter
The marker style. marker can be either an instance of the class or the text shorthand for a particular marker. See matplotlib.markers for more information about marker styles. cmapstr or Colormap, default: rcParams["image.cmap"] (default: 'viridis')
GeeksforGeeks
geeksforgeeks.org › python › matplotlib-pyplot-viridis-in-python
matplotlib.pyplot.viridis() in Python - GeeksforGeeks
July 12, 2025 - # Implementation of matplotlib function import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np ang = 32 rad = 10 radm = 0.35 radii = np.linspace(radm, 0.95, rad) angles = np.linspace(0, 1.4 * np.pi, ang) angles = np.repeat(angles[..., np.newaxis], rad, axis = 1) angles[:, 1::2] += np.pi / ang x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() z = (np.sin(4 * radii) * np.cos(4 * angles)).flatten() triang = tri.Triangulation(x, y) triang.set_mask(np.hypot(x[triang.triangles].mean(axis = 1), y[triang.triangles].mean(axis = 1)) < radm) tpc = plt.tripcolor(triang, z, shading ='flat') plt.colorbar(tpc) plt.viridis() plt.title('matplotlib.pyplot.viridis() function Example', fontweight ="bold") plt.show() Output: Example #2:
Matplotlib
matplotlib.org › stable › users › explain › colors › colormaps.html
Choosing Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
plot_color_gradients('Perceptually Uniform Sequential', ['viridis', 'plasma', 'inferno', 'magma', 'cividis'])
Matplotlib
matplotlib.org › 3.5.0 › api › _as_gen › matplotlib.pyplot.viridis.html
matplotlib.pyplot.viridis — Matplotlib 3.5.0 documentation
January 5, 2020 - Set the colormap to 'viridis'.
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
Matplotlib
matplotlib.org › 2.1.1 › api › _as_gen › matplotlib.pyplot.viridis.html
matplotlib.pyplot.viridis — Matplotlib 2.1.1 documentation
You are reading an old version of the documentation (v2.1.1). For the latest version see https://matplotlib.org/stable/ ... set the default colormap to viridis and apply to current image if any.
Top answer 1 of 4
16
To set viridis as your colormap using set_cmap, you must register it first:
import colormaps as cmaps
plt.register_cmap(name='viridis', cmap=cmaps.viridis)
plt.set_cmap(cmaps.viridis)
img=mpimg.imread('stinkbug.png')
lum_img = np.flipud(img[:,:,0])
imgplot = plt.pcolormesh(lum_img)
2 of 4
12
Rather than using set_cmap, which requires a matplotlib.colors.Colormap instance, you can set the cmap directly in the pcolormesh call
(cmaps.viridis is a matplotlib.colors.ListedColormap)
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import colormaps as cmaps
img=mpimg.imread('stinkbug.png')
lum_img = np.flipud(img[:,:,0])
imgplot = plt.pcolormesh(lum_img, cmap=cmaps.viridis)
Matplotlib
matplotlib.org › 3.1.1 › api › _as_gen › matplotlib.pyplot.viridis.html
matplotlib.pyplot.viridis — Matplotlib 3.1.2 documentation
January 5, 2020 - You are reading an old version of the documentation (v3.1.1). For the latest version see https://matplotlib.org/stable/ ... Set the colormap to "viridis".
Matplotlib
matplotlib.org › stable › users › explain › colors › colormap-manipulation.html
Creating Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl from matplotlib.colors import LinearSegmentedColormap, ListedColormap viridis = mpl.colormaps['viridis'].resampled(8)
Bids
bids.github.io › colormap
matplotlib colormaps
Update: These colormaps have been merged into the development version of Matplotlib, all of them will be included in matplotlib 1.5, and "option D" (now called "viridis") will be the new default colormap in matplotlib 2.0. If you just want the colormaps themselves, they're available in a single ...
Matplotlib
matplotlib.org › 3.1.1 › tutorials › colors › colormap-manipulation.html
Creating Colormaps in Matplotlib — Matplotlib 3.1.2 documentation
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from matplotlib.colors import ListedColormap, LinearSegmentedColormap viridis = cm.get_cmap('viridis', 12) print(viridis)
Matplotlib
matplotlib.org › stable › tutorials › colors › colormap-manipulation.html
Creating Colormaps in Matplotlib — Matplotlib 3.7.2 documentation
May 1, 2020 - import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl from matplotlib.colors import ListedColormap, LinearSegmentedColormap viridis = mpl.colormaps['viridis'].resampled(8)
Kennethmoreland
kennethmoreland.com › color-advice
Color Map Advice for Scientific Visualization | Kenneth Moreland
This color map is available in ParaView as the “Viridis” preset. Python code to generate these colors. This color map was first featured in the matplotlib library and is covered by matplotlib’s BSD-compatible license.
Bomberbot
bomberbot.com › python › exploring-the-power-of-viridis-in-matplotlib-a-deep-dive-into-data-visualization
Exploring the Power of Viridis in Matplotlib: A Deep Dive into Data Visualization - Bomberbot
July 17, 2025 - The viridis colormap in Matplotlib represents a significant advancement in the field of data visualization. Its perceptual uniformity, accessibility, and aesthetic appeal make it an excellent choice for a wide range of visualization tasks.
Reddit
reddit.com › r/cfd › colormaps explained courtesy of matplotlib. you spend a lot of time on your simulations, make sure you spend a little bit of time selecting the correct colormap for your figures.
r/CFD on Reddit: Colormaps explained courtesy of matplotlib. You spend a lot of time on your simulations, make sure you spend a little bit of time selecting the correct colormap for your figures.
October 30, 2020 - If you walk into a meeting and announce "ya'll are idiots for liking pretty pictures, look at my shitty looking viridis scale now" you're gonna have a really bad time. ... Why do we have to pass plt.cm.gray to the imshow() call when visualizing a grayscale picture? (python+matplotlib)
MIT
stuff.mit.edu › afs › athena › software › r › current › lib › R › library › viridisLite › html › viridis.html
R: Matplotlib 'viridis' color map
viridis(n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") viridisMap(n = 256, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") magma(n, alpha = 1, begin = 0, end = 1, direction = 1) inferno(n, alpha = 1, begin = 0, end = 1, direction = 1) plasma(n, alpha = 1, begin = 0, end = 1, direction = 1)