The standard colormaps also all have reversed versions. They have the same names with _r tacked on to the end. (Documentation here.)
Top answer 1 of 7
781
The standard colormaps also all have reversed versions. They have the same names with _r tacked on to the end. (Documentation here.)
2 of 7
54
The solution is pretty straightforward. Suppose you want to use the "autumn" colormap scheme. The standard version:
cmap = matplotlib.cm.autumn
To reverse the colormap color spectrum, use get_cmap() function and append '_r' to the colormap title like this:
cmap_reversed = matplotlib.cm.get_cmap('autumn_r')
Matplotlib
matplotlib.org › stable › gallery › color › colormap_reference.html
Colormap reference — Matplotlib 3.11.2 documentation
The built-in reversed colormaps are generated using Colormap.reversed.
Matplotlib
matplotlib.org › stable › users › explain › colors › colormaps.html
Choosing Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
Do separately for each category # so each plot can be pretty. To make scatter markers change # color along plot: # https://stackoverflow.com/q/8202605/ if cmap_category == 'Sequential': # These colormaps all start at high lightness, but we want them # reversed to look nice in the plot, so reverse ...
Matplotlib
matplotlib.org › stable › users › explain › colors › colormap-manipulation.html
Creating Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
colors = ["#ffffcc", "#a1dab4", "#41b6c4", "#2c7fb8", "#253494"] my_cmap = ListedColormap(colors, name="my_cmap") my_cmap_r = my_cmap.reversed() plot_examples([my_cmap, my_cmap_r])
Skytowner
skytowner.com › explore › inverting_color_maps_in_matplotlib
Inverting color maps in Matplotlib
To invert a color map in Matplotlib, attach the _r suffix to the color map, like so: ... Here, the key is that we used gray_r instead of gray, which reverses the color map.
Google Groups
groups.google.com › g › scitools-iris › c › biD6F6OG9Og
Reverse Brewer colour map...
Hope it helps someone else in future and saves them a few hours... Nick ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... Or just put an '_r'at the end of any built-in matplotlib colormap name. Reverses ...
Narkive
matplotlib-users.narkive.com › CxHiK8is › how-to-reverse-the-colorbar-and-its-label-at-the-same-time
[Matplotlib-users] how to reverse the colorbar and its label at the same time?
all code in pylab mode. import numpy as np import matplotlib as mat a = np.arange(100).reshape(10,10) contourf(a,levels=np.arange(0,101,10)) colorbar() in the above figure, colorbar label shows 0 at the bottom and 100 at the top. Yet I want the 0 at the top and the 100 at the bottom, with the same sequence of colors in the colorbar. One way is to reverse the cmap, and then reverse the colorbar labels at a = np.arange(100).reshape(10,10) contourf(a,levels=np.arange(0,101,10),cmap=mat.cm.jet_r) cbar = colorbar() cbar.set_ticks(np.arange(0,101,10)) cbar.set_ticklabels(np.arange(100,-1,-10)) Chao, import numpy as np import matplotlib.pyplot as plt a = np.arange(100).reshape(10,10) fig, ax1 = plt.subplots() CS = ax1.contourf(a,levels=np.arange(0,101,10)) cbar = plt.colorbar(CS) cbar.ax.invert_yaxis() Does that produce the desired results?
Matplotlib
matplotlib.org › 3.1.0 › _modules › matplotlib › cm.html
matplotlib.cm — Matplotlib 3.1.0 documentation
May 18, 2019 - if 'red' in spec: return colors.LinearSegmentedColormap(name, spec, lutsize) elif 'listed' in spec: return colors.ListedColormap(spec['listed'], name) else: return colors.LinearSegmentedColormap.from_list(name, spec, lutsize) LUTSIZE = mpl.rcParams['image.lut'] # Generate the reversed specifications (all at once, to avoid # modify-when-iterating). datad.update({cmapname + '_r': _reverse_cmap_spec(spec) for cmapname, spec in datad.items()}) # Precache the cmaps with ``lutsize = LUTSIZE``. # Also add the reversed ones added in the section above: for cmapname in datad: cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE) cmap_d.update(cmaps_listed) locals().update(cmap_d) # Continue with definitions ...
TutorialsPoint
tutorialspoint.com › article › how-to-reverse-the-colormap-of-an-image-to-scalar-values-in-matplotib
How to reverse the colormap of an image to scalar values in Matplotib?
March 25, 2026 - Reversing colormaps in Matplotlib is straightforward using either the .reversed() method or the '_r' suffix.
PyMorton
pymorton.wordpress.com › 2015 › 08 › 27 › reversing-a-matplotlib-colormap
Reversing a matplotlib colormap - PyMorton - WordPress.com
February 26, 2016 - Initially, I couldn’t find an easy way to use it since it isn’t in the current version (1.4.3). I found the underlying data list it in “_cm_listed.py” in the Matplotlib Github listed as “_viridis_data”and built the colormap from the data list: viridis_cm = LinearSegmentedColormap.from_list('viridis', cm_data) Here is the figure I was working on with the viridis colormap: Looking at the figure, what I really wanted was the reverse of the colormap.
Bomberbot
bomberbot.com › python › mastering-colormap-reversal-in-matplotlib-a-comprehensive-guide-for-python-enthusiasts
Mastering Colormap Reversal in Matplotlib: A Comprehensive Guide for Python Enthusiasts - Bomberbot
Sometimes, you might want to create a custom colormap and then reverse it. Here's how you can do that: import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np # Create a custom colormap colors = ['#ff0000', '#00ff00', '#0000ff'] # Red, Green, Blue n_bins = 100 # Number of discretizations custom_cmap = mcolors.LinearSegmentedColormap.from_list('custom', colors, N=n_bins) # Create the reversed version custom_cmap_r = custom_cmap.reversed() # Create sample data x = np.linspace(0, 10, 100) y = np.tan(x) # Create the plot plt.figure(figsize=(12, 6)) plt.subplot(121) plt.scatter(x, y, c=y, cmap=custom_cmap) plt.colorbar() plt.title('Custom Colormap') plt.subplot(122) plt.scatter(x, y, c=y, cmap=custom_cmap_r) plt.colorbar() plt.title('Reversed Custom Colormap') plt.tight_layout() plt.show()
HoloViews
holoviews.org › user_guide › Colormaps.html
Colormaps — HoloViews v1.23.2
provider: package offering the colormap (‘matplotlib’, ‘bokeh’, or ‘colorcet’) source: original source or creator of the colormaps (‘cet’, ‘colorbrewer’, ‘d3’, ‘bids’,’misc’) bg: base/background color expected for the map (‘light’,’dark’,’medium’,’any’) reverse: whether the colormap name includes _r indicating that it is a reverse of a base map (True, False) The hv.plotting.list_cmaps...
AdamSmith.haus
adamsmith.haus › python › answers › how-to-reverse-a-colormap-using-matplotlib-in-python
How to reverse a Colormap using Matplotlib in Python
Python answers, examples, and documentation
Python Examples
pythonexamples.org › python-matplotlib-color-map
Python Matplotlib - Understanding and Using Colormaps
import matplotlib.pyplot as plt import numpy as np # Data x = np.linspace(0, 10, 100) y = np.sin(x) z = y ** 2 # Create line plot with reversed colormap plt.scatter(x, y, c=z, cmap='coolwarm_r', s=50) # Add colorbar plt.colorbar(label='Intensity') # Add labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Scatter Plot with Reversed Colormap') # Show plot plt.show()