You can also use plt.set_cmap, see here or (more elaborately, scroll down) here:

import numpy as np
import matplotlib.pyplot as plt

plt.imshow(np.random.random((10,10)), cmap='magma')
plt.colorbar()
plt.set_cmap('viridis')
Answer from S.A. on Stack Overflow
🌐
Analytics Vidhya
analyticsvidhya.com › home › cmap in python: tutorials & examples | colormaps in matplotlib (updated 2026)
Cmap in Python: Tutorials & Examples | Colormaps in Matplotlib (Updated 2026)
January 2, 2026 - As I mentioned, if you didn’t define the colormaps you used, you will get the default matplotlib colormaps. The default colormap name is ‘viridis’. Next, I will change the colormaps from ‘viridis’ to ‘inferno’ colormaps with this code.
🌐
Matplotlib
matplotlib.org › stable › tutorials › colors › colormaps.html
Matplotlib
May 25, 2022 - Matplotlib has support for visualizing information with a wide array of colors and colormaps.
🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colormaps.html
Choosing Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
Note that overlaid, labeled contours could help differentiate between one side of the colormap vs. the other since color cannot be used once a plot is printed to grayscale. Many of the Qualitative and Miscellaneous colormaps, such as Accent, hsv, jet and turbo, change from darker to lighter and back to darker grey throughout the colormap.
🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colormap-manipulation.html
Creating Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
First, getting a named colormap, most of which are listed in Choosing Colormaps in Matplotlib, may be done using matplotlib.colormaps, which returns a colormap object. The length of the list of colors used internally to define the colormap can be adjusted via Colormap.resampled.
🌐
DataCamp
datacamp.com › tutorial › matplotlib-colormaps
Matplotlib Colormaps: Customizing Your Color Schemes | DataCamp
November 9, 2024 - Matplotlib custom colormap with ListedColormap. Image by Author. LinearSegmentedColormap allows you to create colormaps that transition smoothly between colors. This is worth knowing because continuous data often requires gradient color changes.
Find elsewhere
🌐
Pythoncharts
pythoncharts.com › matplotlib › matplotlib-colors-colormaps
Python Charts - Colors and Color Maps in Matplotlib
Colormaps are preset lists/sequences/maps of colors that Matplotlib already has packaged up for us, ready to use.
🌐
Medium
medium.com › data-science › beautiful-custom-colormaps-with-matplotlib-5bab3d1f0e72
Beautiful custom colormaps with Matplotlib | by Kerry Halupka | TDS Archive | Medium
July 28, 2020 - Beautiful custom colormaps with Matplotlib Level up your chart game with custom colormaps to match your theme. If your Matplotlib chart needs a colormap and you’re not using an inbuilt map, chances …
🌐
Matplotlib
matplotlib.org › stable › gallery › color › custom_cmap.html
Create a colormap from a list of colors — Matplotlib 3.11.2 documentation
# This sets the new default *and* sets the colormap of the last # image-like item plotted via pyplot, if any. # # Draw a line with low zorder so it will be behind the image. axs[1, 1].plot([0, 10 * np.pi], [0, 20 * np.pi], color='c', lw=20, zorder=-1) im4 = axs[1, 1].imshow(Z) fig.colorbar(im4, ax=axs[1, 1]) # Here it is: changing the colormap for the current image and its # colorbar after they have been plotted.
🌐
TutorialsPoint
tutorialspoint.com › matplotlib › matplotlib_colormaps.htm
Matplotlib - ColorMaps
Here is an example that changes the default colormap to RdYlBu_r by modifying the global Matplotlib settings like mpl.rc('image', cmap='RdYlBu_r').
🌐
Towards Data Science
towardsdatascience.com › home › latest › beautiful custom colormaps with matplotlib
Beautiful custom colormaps with Matplotlib | Towards Data Science
March 5, 2025 - Let's create a continuous colormap containing all of the colors above. We'll be using the matplotlib.colors function called LinearSegmentedColormap. This function accepts a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table.
🌐
Purdue
docs.rcac.purdue.edu › workshops › matplotlib › colormaps
Colormaps - RCAC Documentation
Using colormaps is quite simple: add the cmap='CMAP_NAME' option to the plotting function you are using and MatPlotLib will handle the rest. In the following script, we use four different colormaps with the same contourf function on the same data. The invocation stays mostly the same, it just ...
🌐
Matplotlib
matplotlib.org › stable › gallery › color › individual_colors_from_cmap.html
Selecting individual colors from a colormap — Matplotlib 3.11.2 documentation
Note that all the colors from Matplotlib's qualitative color maps are also available as color sequences, so may be accessed more directly from the color sequence registry. See Named color sequences. colors = mpl.colormaps['Dark2'].colors fig, ax = plt.subplots(layout='constrained') for i, color in enumerate(colors): ax.plot([0, i], color=color) plt.show()
🌐
Towards Data Science
towardsdatascience.com › home › data science › creating colormaps in matplotlib
Creating Colormaps in Matplotlib | Towards Data Science
October 11, 2020 - Next, I will change the colormaps from ' viridis ' to 'inferno' colormaps with this code ... Now, to modify the colormaps, you need to import these following sublibraries in Matplotlib.