Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What names can be used in plt.cm.get_cmap?
Matplotlib provides numerous built-in colormaps through plt.cm.get_cmap(), and additional colormaps can be registered using matplotlib.cm.register_cmap. You can retrieve a list of all available colormap names to use with get_cmap().
Getting All Available Colormap Names
Use plt.colormaps() to retrieve all registered colormap names ?
from matplotlib import pyplot as plt
cmaps = plt.colormaps()
print("Available colormap names:")
print(f"Total colormaps: {len(cmaps)}")
# Show first 10 colormaps
for i, name in enumerate(cmaps[:10]):
print(f"{i+1}. {name}")
print("...")
print(f"And {len(cmaps)-10} more colormaps")
Available colormap names: Total colormaps: 170 1. Accent 2. Accent_r 3. Blues 4. Blues_r 5. BrBG 6. BrBG_r 7. BuGn 8. BuGn_r 9. BuPu 10. BuPu_r ... And 160 more colormaps
Using Colormap Names with get_cmap()
Once you have the colormap names, use them with plt.cm.get_cmap() ?
import matplotlib.pyplot as plt
import numpy as np
# Create sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Use different colormaps
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
# Using different colormap names
colormaps = ['viridis', 'plasma', 'coolwarm']
for i, cmap_name in enumerate(colormaps):
cmap = plt.cm.get_cmap(cmap_name)
axes[i].scatter(x, y, c=y, cmap=cmap)
axes[i].set_title(f'Colormap: {cmap_name}')
plt.tight_layout()
plt.show()
Popular Colormap Categories
Matplotlib colormaps are organized into several categories ?
| Category | Examples | Best For |
|---|---|---|
| Sequential | viridis, plasma, Blues, Reds | Ordered data |
| Diverging | RdBu, coolwarm, seismic | Data with critical midpoint |
| Qualitative | Set1, Set2, Accent, tab10 | Categorical data |
| Cyclic | hsv, twilight | Periodic data |
Filtering Colormap Names
You can filter colormaps by category or pattern ?
import matplotlib.pyplot as plt
# Get all colormap names
all_cmaps = plt.colormaps()
# Filter sequential colormaps (ending with 's' often indicates sequential)
sequential = [name for name in all_cmaps if name in ['viridis', 'plasma', 'inferno', 'magma', 'Blues', 'Reds', 'Greens']]
# Filter reversed colormaps (ending with '_r')
reversed_cmaps = [name for name in all_cmaps if name.endswith('_r')]
print("Popular sequential colormaps:")
for cmap in sequential:
print(f" {cmap}")
print(f"\nReversed colormaps available: {len(reversed_cmaps)}")
print("Examples:", reversed_cmaps[:5])
Popular sequential colormaps: viridis plasma inferno magma Blues Reds Greens Reversed colormaps available: 85 Examples: ['Accent_r', 'Blues_r', 'BrBG_r', 'BuGn_r', 'BuPu_r']
Conclusion
Use plt.colormaps() to get all available colormap names for plt.cm.get_cmap(). Matplotlib provides over 170 built-in colormaps across sequential, diverging, qualitative, and cyclic categories. Choose colormaps based on your data type and visualization needs.
