Edit

It's now possible to do it easily with plotly.figure_factory: https://plot.ly/python/annotated_heatmap/

As far as I know, it is still not possible to convert Matplotlib's heatmaps into Plotly's though.

Aug 2015 Answer

Here's an example of making an annotated heatmap with the python api:

import plotly.plotly as py
import plotly.graph_objs as go

x = ['A', 'B', 'C', 'D', 'E']
y = ['W', 'X', 'Y', 'Z']

#       x0    x1    x2    x3    x4
z = [[0.00, 0.00, 0.75, 0.75, 0.00],  # y0
     [0.00, 0.00, 0.75, 0.75, 0.00],  # y1
     [0.75, 0.75, 0.75, 0.75, 0.75],  # y2
     [0.00, 0.00, 0.00, 0.75, 0.00]]  # y3

annotations = go.Annotations()
for n, row in enumerate(z):
    for m, val in enumerate(row):
        annotations.append(go.Annotation(text=str(z[n][m]), x=x[m], y=y[n],
                                         xref='x1', yref='y1', showarrow=False))

colorscale = [[0, '#3D9970'], [1, '#001f3f']]  # custom colorscale
trace = go.Heatmap(x=x, y=y, z=z, colorscale=colorscale, showscale=False)

fig = go.Figure(data=go.Data([trace]))
fig['layout'].update(
    title="Annotated Heatmap",
    annotations=annotations,
    xaxis=go.XAxis(ticks='', side='top'),
    yaxis=go.YAxis(ticks='', ticksuffix='  '),  # ticksuffix is a workaround to add a bit of padding
    width=700,
    height=700,
    autosize=False
)
print py.plot(fig, filename='Stack Overflow 31756636', auto_open=False)  # https://plot.ly/~theengineear/5179

With the result at https://plot.ly/~theengineear/5179

Linking a related GitHub issue: https://github.com/plotly/python-api/issues/273

Answer from theengineear on Stack Overflow
🌐
Plotly
plotly.com › python › annotated-heatmap
Annotated heatmaps in Python
import plotly.express as px import numpy as np np.random.seed(1) z = np.random.randn(20, 20) fig = px.imshow(z, text_auto=".2f", color_continuous_scale='Greys', aspect="auto") fig.show() px.imshow() can produce more elaborate annotated heatmaps.
Top answer
1 of 2
11

Edit

It's now possible to do it easily with plotly.figure_factory: https://plot.ly/python/annotated_heatmap/

As far as I know, it is still not possible to convert Matplotlib's heatmaps into Plotly's though.

Aug 2015 Answer

Here's an example of making an annotated heatmap with the python api:

import plotly.plotly as py
import plotly.graph_objs as go

x = ['A', 'B', 'C', 'D', 'E']
y = ['W', 'X', 'Y', 'Z']

#       x0    x1    x2    x3    x4
z = [[0.00, 0.00, 0.75, 0.75, 0.00],  # y0
     [0.00, 0.00, 0.75, 0.75, 0.00],  # y1
     [0.75, 0.75, 0.75, 0.75, 0.75],  # y2
     [0.00, 0.00, 0.00, 0.75, 0.00]]  # y3

annotations = go.Annotations()
for n, row in enumerate(z):
    for m, val in enumerate(row):
        annotations.append(go.Annotation(text=str(z[n][m]), x=x[m], y=y[n],
                                         xref='x1', yref='y1', showarrow=False))

colorscale = [[0, '#3D9970'], [1, '#001f3f']]  # custom colorscale
trace = go.Heatmap(x=x, y=y, z=z, colorscale=colorscale, showscale=False)

fig = go.Figure(data=go.Data([trace]))
fig['layout'].update(
    title="Annotated Heatmap",
    annotations=annotations,
    xaxis=go.XAxis(ticks='', side='top'),
    yaxis=go.YAxis(ticks='', ticksuffix='  '),  # ticksuffix is a workaround to add a bit of padding
    width=700,
    height=700,
    autosize=False
)
print py.plot(fig, filename='Stack Overflow 31756636', auto_open=False)  # https://plot.ly/~theengineear/5179

With the result at https://plot.ly/~theengineear/5179

Linking a related GitHub issue: https://github.com/plotly/python-api/issues/273

2 of 2
2

You have to use Plotly's declarative syntax, instead of converting from matplotlib to Python. Plotly only supports the matplotlib figure objects that it can reverse engineer, and unfortunately heatmaps aren't one of them. Here are the Plotly Python heatmap docs: https://plot.ly/python/heatmaps/ And here are the Plotly Python annotation docs: https://plot.ly/python/text-and-annotations/ Make sure to set the annotations to be referenced to the data rather than the page.

You could also overlay a scatter plot with a hover text field on the heatmap, but set the mode of the scatter plot to text. This would make only the text show and not the scatter plot points. Docs: https://plot.ly/python/text-and-annotations/

🌐
GeeksforGeeks
geeksforgeeks.org › python › annotated-heatmaps-using-plotly-in-python
Annotated Heatmaps using Plotly in Python - GeeksforGeeks
September 5, 2020 - import plotly.figure_factory as ff import numpy as np feature_x = np.arange(0, 10, 2) feature_y = np.arange(0, 10, 3) # Creating 2-D grid of features [X, Y] = np.meshgrid(feature_x, feature_y) Z = np.cos(X / 2) + np.sin(Y / 4) fig = ff.create_annotated_heatmap(Z, colorscale='rainbow') fig.show()
🌐
GitHub
github.com › plotly › plotly.py › blob › main › doc › python › annotated-heatmap.md
plotly.py/doc/python/annotated-heatmap.md at main · plotly/plotly.py
As of version 5.5.0 of plotly, the recommended way to display annotated heatmaps is to use px.imshow() rather than the now-deprecated create_annotated_heatmap figure factory documented below for historical reasons.
Author: plotly
🌐
CodePen
codepen.io › plotly › pen › RPdwaz
Annotated Heat Map with Plotly.js Charts
var xValues = ['A', 'B', 'C', 'D', 'E']; var yValues = ['W', 'X', 'Y', 'Z']; var zValues = [ [0.00, 0.00, 0.75, 0.75, 0.00], [0.00, 0.00, 0.75, 0.75, 0.00], [0.75, 0.75, 0.75, 0.75, 0.75], [0.00, 0.00, 0.00, 0.75, 0.00] ]; var colorscaleValue = [ [0, '#3D9970'], [1, '#001f3f'] ]; var data = [{ x: xValues, y: yValues, z: zValues, type: 'heatmap', colorscale: colorscaleValue, showscale: false }]; var layout = { title: 'Annotated Heatmap', annotations: [], xaxis: { ticks: '', side: 'top' }, yaxis: { ticks: '', ticksuffix: ' ', width: 700, height: 700, autosize: false } }; for ( var i = 0; i < yVa
🌐
Plotly
plotly.com › javascript › heatmaps
Heatmaps in JavaScript
var data = [ { z: [[1, null, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]], x: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], y: ['Morning', 'Afternoon', 'Evening'], type: 'heatmap', hoverongaps: false } ]; Plotly.newPlot('myDiv', data);
🌐
Plotly
community.plotly.com › 📊 plotly python
How to create annotated heatmaps in subplots? - 📊 Plotly Python - Plotly Community Forum
March 25, 2020 - Hello. I’m trying to create a subplot of annotated heatmaps using Dash + Plotly. Without using annotated heatmaps (from Figure Factory), the following code get what I want: ... fig = make_subplots(rows=1, cols=2) fig.add_trace(go.Heatmap(x=x1, y=y1, z=z1, colorscale='RdBu'), row=1, col=1) fig.add_trace(go.Heatmap(x=x2, y=y2, z=z2, colorscale='RdBu'), row=1, col=2) ... But, when I try to use annotated heatmaps, it becames hard.
Find elsewhere
🌐
Plotly
plotly.com › matlab › annotated-heatmap
Annotated heatmaps in MATLAB
Over 10 examples of Annotated Heatmaps including changing color, size, log axes, and more in MATLAB.
🌐
Kaggle
kaggle.com › getting-started › 285498
Visualizations tip #1: Annotated heatmaps | Plotly | Kaggle
Hello, When I make a EDA or visualization notebook, I usually choose one visualization library and stick to it until the end. That is what I prefer. Of cour...
🌐
Plotly
docs.plotly.com › studio › heatmaps
Heatmaps - Plotly Studio Documentation
Products by Factory and Delivery Location Chart: - Type: heatmap - X: Delivery location - Y: Factory location - Values: Count of products Data: - Aggregation: count by Factory location and Delivery location Options: - Dropdown to select color scale (Viridis, RdBu, YlOrRd) - Default Viridis - Checkbox to toggle text annotations - Default show values
🌐
Bomberbot
bomberbot.com › python › mastering-plotlys-annotated-heatmaps-in-python-a-comprehensive-guide
Mastering Plotly's Annotated Heatmaps in Python: A Comprehensive Guide - Bomberbot
Plotly's create_annotated_heatmap() function is a versatile tool that transforms 2D arrays of data into visually striking and informative heatmaps.
🌐
Stack Overflow
stackoverflow.com › questions › 77993261 › plotly-annotated-heatmap
python - Plotly annotated heatmap - Stack Overflow
from plotly import exceptions, optional_imports import plotly.colors as clrs from plotly.figure_factory import utils from plotly.graph_objs import graph_objs from plotly.validators.heatmap import ColorscaleValidator # Optional imports, may be None for users that only use our core functionality. np = optional_imports.get_module("numpy") def validate_annotated_heatmap(z, x, y, annotation_text): """ Annotated-heatmap-specific validations Check that if a text matrix is supplied, it has the same dimensions as the z matrix.
🌐
GeeksforGeeks
geeksforgeeks.org › data visualization › how-to-show-text-on-a-heatmap-with-plotly
How to Show Text on a Heatmap with Plotly - GeeksforGeeks
July 23, 2025 - One of Plotly's strengths is its ability to create interactive visualizations that can be embedded in web applications or shared online. Annotated heatmaps display additional information by overlaying text on the heatmap cells.
🌐
Plotly
community.plotly.com › 📊 plotly python
Annotate heatmap without using figure factory - 📊 Plotly Python - Plotly Community Forum
April 12, 2019 - How can I add values to the heatmap below without using figure factory? I can’t tell in this example (or from documentation) what is actually making the numbers appear in the heatmap cells. Please help! https://plot.ly/~empet/14772/annotated-heatmap/#/
🌐
GitHub
github.com › plotly › plotly.py › issues › 2313
How to create annotated heatmaps in subplots? · Issue #2313 · plotly/plotly.py
March 25, 2020 - Without using annotated heatmaps (from Figure Factory), the following code get what I want: ... fig = make_subplots(rows=1, cols=2) fig.add_trace(go.Heatmap(x=x1, y=y1, z=z1, colorscale='RdBu'), row=1, col=1) fig.add_trace(go.Heatmap(x=x2, y=y2, z=z2, colorscale='RdBu'), row=1, col=2) ...
Author: plotly
🌐
Plotly
plotly.github.io › plotly.py-docs › generated › plotly.graph_objects.Heatmap.html
plotly.graph_objects.Heatmap — 7.0.0 documentation
Then, by default, the resulting heatmap will have N partitions along the y axis and M partitions along the x axis. In other words, the i-th row/ j-th column cell in z is mapped to the i-th partition of the y axis (starting from the bottom of the plot) and the j-th partition of the x-axis (starting from the left of the plot).
🌐
GitHub
github.com › plotly › plotly.py › issues › 3651
Heatmap (both go and px) not showing text annotations on Hugo site · Issue #3651 · plotly/plotly.py
March 31, 2022 - <!-- call from within post.md --> {{< plotly json="/json/heatmap2.json" height="700px" >}} ... Create an annotated heatmap fig on a VSCode Python script (using either graph_objects or plotly.express)
Author: plotly
🌐
Plotly
community.plotly.com › 📊 plotly python
How to add annotations to a heatmap? - 📊 Plotly Python - Plotly Community Forum
March 24, 2020 - Hi! I have a pretty standard heatmap and I cannot figure out how to add for each box the z-value as a label. Not just as hover but fixed on the heatmap. I am using plotly in what I think is a pretty standard way. I couldn’t figure it out from the doc. Here is the code: data=[go.Heatmap(x=x_values,y=y_values, z=z_values,colorscale=‘Jet_r’)] layout=go.Layout(title=‘My Data’,autosize=False, width=700, height=600, xaxis = dict( tickmode = ‘linear’, dtick = 1)) fig=go.Figure(data=data,layout...