To get gradiated colours you can do:

import matplotlib.pyplot as plt
# Builtin colourmap "seismic" has the blue-white-red
#   scale you want
plt.pcolor(np.array(data), cmap=plt.cm.seismic, vmin=0, vmax=2)
plt.colorbar()
plt.show()

Here I've set vmin and vmax so that they're equally spaced around the white value at 1.0, unfortunately I think this means that any values above 2.0 don't become any darker than those at 2.0. You may get better results by choosing a wider range, even if this means the scale includes negative values, e.g. vmin=-2, vmax=4.

Answer from Marius on Stack Overflow
🌐
Scaler
scaler.com › home › topics › matplotlib › matplotlib heatmap
Matplotlib Heatmap - Scaler Topics
December 20, 2022 - The imshow() function in pyplot ... The Colormap instance of the plot. norm : str or Normalize The normalization method used to scale scalar data to the [0, 1] range before using cmap to map to colours....
🌐
Seaborn
seaborn.pydata.org › generated › seaborn.heatmap.html
seaborn.heatmap — seaborn 0.13.2 documentation - PyData |
All other keyword arguments are passed to matplotlib.axes.Axes.pcolormesh(). Returns: axmatplotlib Axes · Axes object with the heatmap. See also · clustermap · Plot a matrix using hierarchical clustering to arrange the rows and columns.
🌐
Matplotlib
matplotlib.org › stable › gallery › images_contours_and_fields › image_annotated_heatmap.html
Annotated heatmap — Matplotlib 3.11.2 documentation
def heatmap(data, row_labels, col_labels, ax=None, cbar_kw=None, cbarlabel="", **kwargs): """ Create a heatmap from a numpy array and two lists of labels. Parameters ---------- data A 2D numpy array of shape (M, N). row_labels A list or array of length M with the labels for the rows. col_labels A list or array of length N with the labels for the columns. ax A `matplotlib.axes.Axes` instance to which the heatmap is plotted.
People also ask

How do I make a heatmap in Matplotlib?
Pass a two-dimensional array to ax.imshow() and add a colorbar that explains the mapping from values to colors.
🌐
pythonpool.com
pythonpool.com › home › matplotlib › matplotlib heatmap with imshow(): colorbars, labels, and annotations
Matplotlib Heatmap with imshow(): Colorbars, Labels, and Annotations
How do I add labels to a Matplotlib heatmap?
Set tick positions and labels with set_xticks(), set_xticklabels(), set_yticks(), and set_yticklabels().
🌐
pythonpool.com
pythonpool.com › home › matplotlib › matplotlib heatmap with imshow(): colorbars, labels, and annotations
Matplotlib Heatmap with imshow(): Colorbars, Labels, and Annotations
How do I change the color palette of a heatmap in Matplotlib?
Pass cmap to imshow(), e.g., cmap='coolwarm' or 'magma'. For custom colormaps, use matplotlib.colors (e.g., LinearSegmentedColormap or ListedColormap).
🌐
datavizpyr.com
datavizpyr.com › home › how to make heatmap with matplotlib in python
How to Make a Heatmap in Python with Matplotlib (Step-by-Step Guide)
🌐
Python Pool
pythonpool.com › home › matplotlib › matplotlib heatmap with imshow(): colorbars, labels, and annotations
Matplotlib Heatmap with imshow(): Colorbars, Labels, and Annotations
July 13, 2026 - If labels are long, rotate them and increase the figure width. The Matplotlib figsize guide explains how to choose a canvas size before exporting. Heatmap matrix: A matrix, rows, columns, values, imshow, and a color scale.
🌐
Python-Fiddle
python-fiddle.com › tutorials › matplotlib-heatmap
Creating and Customizing Heatmaps in Matplotlib
import matplotlib.pyplot as plt import numpy as np # Sample data data = np.random.rand(10, 10) plt.imshow(data, cmap='viridis') plt.colorbar() plt.title('Basic Heatmap with imshow') plt.show() - **`imshow(data, cmap='viridis')`** displays the data as an image, where `data` is a 2D array. - **`colorbar()`** adds a color bar to indicate the scale of values.
🌐
GeeksforGeeks
geeksforgeeks.org › data visualization › customizing-heatmap-colors-with-matplotlib
Customizing Heatmap Colors with Matplotlib - GeeksforGeeks
June 13, 2024 - Use Matplotlib's imshow function to create the heatmap using the pivoted dataset, custom colormap, and adjusted color limits. Add a colorbar to the plot to provide a visual scale for interpreting the colors in the heatmap.
🌐
Datavizpyr
datavizpyr.com › home › how to make heatmap with matplotlib in python
How to Make a Heatmap in Python with Matplotlib (Step-by-Step Guide)
August 29, 2025 - How do I reverse the color scale in a heatmap? Append _r to the colormap name (e.g., cmap="viridis_r") to flip it.
Find elsewhere
🌐
YouTube
youtube.com › watch
Create Heatmap with Python Matplotlib | Python Matplotlib | Python Tutorial - YouTube
A heatmap is a graphical representation of data where individual values within a matrix are represented using a color scale. It's an effective tool for visua...
Published: October 30, 2023
🌐
TutorialsPoint
tutorialspoint.com › matplotlib › matplotlib_heatmap.htm
Matplotlib - Heat Map
Clusters in a heatmap may appear as denser regions with similar color patterns, indicating that the corresponding rows or columns share similarities in their values. Now, we are generating random 2D data and then creating clusters in a specific region. visually represents the data intensity using the 'YlGnBu' color map. The resulting plot shows the clustered patterns in the data, with a color bar indicating the intensity scale − · import matplotlib.pyplot as plt import numpy as np # Generating random clustered 2D data data = np.random.random((8, 12)) # Creating clusters in a portion of the data data[:, 3:8] += 1 # Creating a clustered heatmap plt.imshow(data, cmap='YlGnBu', aspect='auto', origin='upper') plt.colorbar(label='Intensity') plt.title('Clustered Heatmap') plt.show()
🌐
Matplotlib
discourse.matplotlib.org › community › matplotlib-users
plotting heatmap matrices in matplotlib with scale - matplotlib-users - Matplotlib
June 6, 2010 - Hi all, How can I plot a matrix of values as a heatmap where values are shown from green to red intensities, or blue to yellow intensities, like in the following figure? http://www.coriell.org/images/microarray.gif I want to have the option of doing this with either green-red maps or blue-yellow ...
🌐
Plotly
plotly.com › python › heatmaps
Heatmaps in Python
Over 11 examples of Heatmaps including changing color, size, log axes, and more in Python.
🌐
Stack Abuse
stackabuse.com › ultimate-guide-to-heatmaps-in-seaborn-with-python
Ultimate Guide to Heatmaps in Seaborn with Python
September 27, 2023 - Now that we have prepared the data it is easy to plot a heatmap using Seaborn. First make sure you've imported the Seaborn library: import seaborn as sns import matplotlib.pyplot as plt
🌐
Matplotlib
matplotlib.org › devdocs › gallery › images_contours_and_fields › image_annotated_heatmap.html
Annotated heatmap — Matplotlib 3.11.0.dev1672+gaf19f1591 documentation
def heatmap(data, row_labels, col_labels, ax=None, cbar_kw=None, cbarlabel="", **kwargs): """ Create a heatmap from a numpy array and two lists of labels. Parameters ---------- data A 2D numpy array of shape (M, N). row_labels A list or array of length M with the labels for the rows. col_labels A list or array of length N with the labels for the columns. ax A `matplotlib.axes.Axes` instance to which the heatmap is plotted.
🌐
Medium
medium.com › @SeanAT19 › how-to-create-heatmaps-using-matplotlib-pyplot-db9ff94d25e8
How to create Heatmaps using matplotlib.pyplot | by Sean Atukorala | Medium
April 30, 2023 - How to create Heatmaps using matplotlib.pyplot In this tutorial we will go over how to create heat maps such as this one using Pandas and matplotlib.pyplot: What is …
🌐
Medium
medium.com › @saisrikanthmurki › plot-a-heat-map-using-python-matplotlib-seaborn-4580eab392d1
Plot a Heat Map Using Python, Matplotlib, Seaborn | by Sai Srikanth | Medium
July 15, 2020 - We can also tweak the color of the heatmap, here I’ve used ‘YIGnBu’ which gives me a heat map in blue scale · And similar to plots in Matplotlib you can also set a title, label x-axis, label y-axis using matplotlib.pyplot
🌐
Matplotlib
matplotlib.org › 3.1.1 › gallery › images_contours_and_fields › image_annotated_heatmap.html
Creating annotated heatmaps — Matplotlib 3.1.2 documentation
May 1, 2020 - def heatmap(data, row_labels, col_labels, ax=None, cbar_kw={}, cbarlabel="", **kwargs): """ Create a heatmap from a numpy array and two lists of labels. Parameters ---------- data A 2D numpy array of shape (N, M). row_labels A list or array of length N with the labels for the rows. col_labels A list or array of length M with the labels for the columns. ax A `matplotlib.axes.Axes` instance to which the heatmap is plotted.
🌐
GeeksforGeeks
geeksforgeeks.org › data visualization › seaborn-heatmap-with-logarithmic-scale-colorbar
Seaborn Heatmap with Logarithmic-Scale Colorbar - GeeksforGeeks
July 23, 2025 - Here is the complete code to generate a Seaborn heatmap with a logarithmic-scale colorbar using the iris dataset: ... import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np import matplotlib.colors as mcolors # Load the iris dataset iris = sns.load_dataset('iris') # Drop the categorical 'species' column iris_numeric = iris.drop(columns=['species']) # Compute the correlation matrix corr_matrix = iris_numeric.corr() # Create the heatmap with a logarithmic color scale plt.figure(figsize=(10, 8)) heatmap = sns.heatmap(corr_matrix, cmap='Blues', annot=True, norm=mcolors.LogNorm()) # Customize the colorbar colorbar = heatmap.collections[0].colorbar colorbar.set_label('Log Scale Colorbar') colorbar.ax.set_ylabel('Logarithmic Scale', rotation=270, labelpad=20) # Display the heatmap plt.title('Seaborn Heatmap with Logarithmic-Scale Colorbar') plt.show()
🌐
VizLearn
vizlearn.in › home › matplotlib › images and heatmaps
Images and Heatmaps | VizLearn
August 31, 2026 - Passing centres instead of edges is the common mistake; matplotlib will accept same-sized arrays and shift everything by half a cell. pcolormesh is slower than imshow and much more flexible. For a regular grid, imshow is the right tool. contourf is the third option, drawing filled contour bands rather than cells — appropriate when the underlying field is genuinely continuous and misleading when it is not. vmin and vmax set the values at the ends of the colormap. Without them, each heatmap scales to its own data, exactly like unshared subplot axes.
🌐
Data Science Dojo
datasciencedojo.com › home › blog › data visualization › demystifying heatmaps: a comprehensive beginner's guide
Demystifying heatmaps: A comprehensive beginner's guide
For example, choosing a poor color scale or omitting important data points can distort the visual representation of the data. It is important to consider these limitations when deciding whether or not to use a heatmap for visualizing your data. Heatmaps are powerful tools for visualizing data patterns and trends. They find applications in various fields, enabling easy interpretation and analysis of large datasets. Matplotlib and Seaborn offer flexible options to create and customize heatmaps.
Published: January 22, 2026