You have to convert a list of colors from seaborn palette to color map of matplolib (thx to @RafaelLopes for proposed changes):

import seaborn as sns
import matplotlib.pylab as plt
import numpy as np
from matplotlib.colors import ListedColormap

# construct cmap
flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]
my_cmap = ListedColormap(sns.color_palette(flatui).as_hex())

N = 500
data1 = np.random.randn(N)
data2 = np.random.randn(N)
colors = np.linspace(0,1,N)
plt.scatter(data1, data2, c=colors, cmap=my_cmap)
plt.colorbar()
plt.show()

Answer from Serenity on Stack Overflow
🌐
Python Graph Gallery
python-graph-gallery.com › the python graph gallery › heatmap › control color in seaborn heatmaps
Control color in seaborn heatmaps
2 weeks ago - # library import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np # Create a dataset df = pd.DataFrame( np.random.random((5, 5)), columns=["a", "b", "c", "d", "e"] ) Edit code✨Still copy-pasting code? Let AI write it for you · You can customize the colors in your heatmap with the cmap parameter of the heatmap() function in seaborn.
Discussions

python - seaborn color_palette as matplotlib colormap - Stack Overflow
Copycolors = ["#67E568","#257F27","#08420D","#FFF000","#FFB62B","#E56124","#E53E30","#7F2353","#F911FF","#9F8CA6"] color_palette = sns.color_palette(colors) I want to transform color_palette to a cmap, which I can use in matplotlib, but I don't see how I can do this. More on stackoverflow.com
🌐 stackoverflow.com
Creating Custom Seaborn Color Palettes from ONLY two Hex Codes? [Question]
import seaborn as sns from matplotlib.colors import LinearSegmentedColormap from matplotlib.cm import register_cmap # relative positions of colors in cmap/palette pos = [0.0,1.0] colors=['#3877C7','#C75B38'] cmap = LinearSegmentedColormap.from_list("", list(zip(pos, colors))) register_cmap("my_cmap", cmap) palette= sns.color_palette("my_cmap",n_colors=50) sns.palplot(palette) plt.show() More on reddit.com
🌐 r/learnpython
2
1
July 5, 2020
`sns.color_palette(as_cmap= True)` returns no cmap
Tested in 0.12.2 v= sns.color_palette(as_cmap= True) print(f"{type(v)} - {v}") outputs - ['#4C72B0', '#55A868', '#C44E52', '#8172B... More on github.com
🌐 github.com
0
August 25, 2023
python - How to set matplotlib colormap as color palette in seaborn - Stack Overflow
Looks like you need colors.... as in the ["red","white"] in the linked question. Then you need to follow the approach in the linked question to fix sns.set_palette(cmap). More on stackoverflow.com
🌐 stackoverflow.com
🌐
Practicalpythonfordatascience
practicalpythonfordatascience.com › ap_seaborn_palette
Seaborn Color Palettes — Practical Python for Data Science
Here are some options for Seaborn palette: · Below is a complete list of all palette options. Most palettes can have the suffix "_r" to indicate the same palette but reversed order. A few palettes can have "_d" appended at the end which indicates a darker version of the original palette
🌐
Codecademy
codecademy.com › article › seaborn-color-palettes-complete-guide-to-data-visualization-colors
Seaborn Color Palettes: Complete Guide to Data Visualization Colors | Codecademy
To change the color scheme of a Seaborn heatmap, use the cmap parameter: sns.heatmap(data, cmap="YlGnBu") Copy to clipboard · Copy to clipboard · You can choose any Matplotlib-compatible colormap name like "coolwarm", "viridis", or "Blues" to suit your data’s tone and purpose.
🌐
GeeksforGeeks
geeksforgeeks.org › python › colormaps-in-seaborn-heatmaps
ColorMaps in Seaborn HeatMaps - GeeksforGeeks
November 25, 2020 - Since "Greens" is an inbuilt colormap in seaborn, can also directly pass "Greens" to the cmap argument: Python3 · import seaborn as sns import numpy as np np.random.seed(0) data = np.random.rand(12, 12) ax = sns.heatmap(data, cmap="Greens") Output: Heatmap with a sequential colormap ·
🌐
Seaborn
seaborn.pydata.org › generated › seaborn.color_palette.html
seaborn.color_palette — seaborn 0.13.2 documentation
Ignored when as_cmap is True. ... Proportion to desaturate each color by. ... If True, return a matplotlib.colors.ListedColormap. ... Set the default color cycle for all plots. ... Reassign color codes like "b", "g", etc. to colors from one of the seaborn palettes. ... with sns.color_palet...
🌐
Apryor6
apryor6.github.io › visualizations › seaborn › heatmap › heatmap
seaborn.heatmap
sns.heatmap(df) <matplotlib.axes._subplots.AxesSubplot at 0x10c53b7b8> cmap adjusts the colormap used. I like diverging colormaps for heatmaps because they provide good contrast. sns.heatmap(df, cmap='coolwarm') <matplotlib.axes._subplots.AxesSubplot at 0x10c65d710> center can be used to indicate at which numeric value to use the center of the colormap.
Find elsewhere
🌐
Seaborn
seaborn.pydata.org › generated › seaborn.heatmap.html
seaborn.heatmap — seaborn 0.13.2 documentation - PyData |
sns.heatmap(glue, cmap="crest") Or pass a colormap object: sns.heatmap(glue, cmap=sns.cubehelix_palette(as_cmap=True)) Set the colormap norm (data values corresponding to minimum and maximum points): sns.heatmap(glue, vmin=50, vmax=100) Use methods on the matplotlib.axes.Axes object to tweak the plot: ax = sns.heatmap(glue, annot=True) ax.set(xlabel="", ylabel="") ax.xaxis.tick_top()
🌐
Reddit
reddit.com › r/learnpython › creating custom seaborn color palettes from only two hex codes? [question]
r/learnpython on Reddit: Creating Custom Seaborn Color Palettes from ONLY two Hex Codes? [Question]
July 5, 2020 -

Hi,

I am wondering if it is possible to create custom diverging seaborn color palettes by only giving it the starting and end colors.

So as an example, If I wanted Hex Code '#3877C7' to be the negative value and '#C75B38' to be the positive, is there a way to tell seaborn (or anything) this and have it automatically fill in the rest of the colors?

I know you can create custom palettes if you list off every combo you want, but that seems very manual if you are changing the two end colors often.

Thanks!

🌐
GitHub
github.com › mwaskom › seaborn › issues › 3448
`sns.color_palette(as_cmap= True)` returns no cmap · Issue #3448 · mwaskom/seaborn
August 25, 2023 - Tested in 0.12.2 v= sns.color_palette(as_cmap= True) print(f"{type(v)} - {v}") outputs - ['#4C72B0', '#55A868', '#C44E52', '#8172B...
Author: mwaskom
🌐
DataCamp
datacamp.com › tutorial › seaborn-heatmaps
Seaborn Heatmaps: A Guide to Data Visualization | DataCamp
December 13, 2024 - # Create an annotated heatmap plt.figure(figsize = (10,8)) plt.rcParams.update({'font.size': 12}) sns.heatmap(correlation_matrix, cmap = 'viridis', vmin = -1, vmax = 1, center = 0, annot=True, fmt=".2f", square=True, linewidths=.5) plt.show()
🌐
GeeksforGeeks
geeksforgeeks.org › data visualization › custom-color-palette-intervals-in-seaborn-heatmap
Custom Color Palette Intervals in Seaborn Heatmap - GeeksforGeeks
July 23, 2025 - import seaborn as sns import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LinearSegmentedColormap, BoundaryNorm # Generate some random data data = np.random.rand(10, 10) # Define custom colors colors = ["#d73027", "#f46d43", "#fdae61", "#fee08b", "#ffffbf", "#d9ef8b", "#a6d96a", "#66bd63", "#1a9850", "#006837"] cmap = LinearSegmentedColormap.from_list("custom", colors, N=100) # Define boundaries and corresponding colors boundaries = [0, 0.2, 0.4, 0.6, 0.8, 1.0] colors = ["#d73027", "#f46d43", "#fee08b", "#d9ef8b", "#66bd63"] cmap = LinearSegmentedColormap.from_list("custom", colors, N=len(colors)) norm = BoundaryNorm(boundaries, cmap.N, clip=True) # Create the heatmap with custom intervals sns.heatmap(data, cmap=cmap, norm=norm) plt.show()
🌐
Indian AI Production
indianaiproduction.com › home › blog › seaborn heatmap using sns.heatmap() | python seaborn tutorial
Seaborn Heatmap using sns.heatmap() | Python Seaborn Tutorial
September 8, 2019 - To change the seaborn heatmap color, the sns.heatmap() cmap (colormap) parameter use. Here, we are passing ‘coolwarm’ colormap value to change the color of sns heatmap but you can pass any value.
🌐
Statology
statology.org › home › how to make heatmaps with seaborn (with examples)
How to Make Heatmaps with Seaborn (With Examples)
January 18, 2021 - sns.heatmap(data, cmap="Spectral") Or we could choose the “coolwarm” color map: sns.heatmap(data, cmap="coolwarm") Find a complete list of cmap options available here.
🌐
Kaggle
kaggle.com › code › analystoleksandra › colour-palettes-of-seaborn
Colour palettes of seaborn
October 22, 2023 - Explore and run AI code with Kaggle Notebooks | Using data from House Prices - Advanced Regression Techniques