Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Class

go.Heatmap

go.Heatmap creates an interactive Cartesian heatmap from two-dimensional values, rendering them as colored rectangular tiles. Add it to a go.Figure and customize coordinates, colors, smoothing, and the color bar.

How it works

go.Heatmap is a low-level graph-object trace for displaying two-dimensional numerical data as colored rectangular tiles. Supply the matrix through z, optionally provide x and y coordinates, and configure visual encoding with attributes such as colorscale, color-bar settings, and smoothing.

Syntax

go.Heatmap(z=None, x=None, y=None, **kwargs)

Key points

  • Use go.Heatmap when Plotly Express does not provide enough starting-point flexibility.
  • px.imshow() supports both heatmaps and full-color images, making it a higher-level alternative.
  • If no explicit scale is supplied, the active template influences the color-scale default.
  • Graph-object traces such as heatmaps accept a colorscale attribute for mapping values to colors.
  • A heatmap's color bar can be customized through its colorbar attributes.
  • The midpoint of the heatmap color domain can be set with zmid.

Common mistakes

  • A heatmap is a Cartesian visualization made from colored rectangular cells, rather than an image-only display.
  • For a higher-level API, px.imshow() is an alternative for creating heatmaps.

Example: Basic heatmap

import plotly.graph_objects as go

fig = go.Figure(go.Heatmap(
    z=[[1,20,30],[20,1,60],[30,60,1]],
    colorscale="Viridis"
))
fig.show()

Creates a heatmap trace from a two-dimensional z-value array and renders it in a Plotly figure.

When to use it

Matrix exploration

Visualize a two-dimensional numerical matrix as colored cells.

Prediction confidence

Display model or classification scores across a two-dimensional grid.

Single-channel image display

Show a single-channel image as a heatmap.

Interview questions

QWhat does go.Heatmap represent?

go.Heatmap is a graph-object trace that maps a two-dimensional z array to colored rectangular tiles. It can be placed in a go.Figure and displayed with fig.show().

Follow-up: How would you choose between this and px.imshow()? Use go.Heatmap when direct trace-level control is useful; use px.imshow() as the higher-level heatmap interface.

QWhich data inputs define a heatmap?

The z matrix supplies the heatmap values. Optional x and y values define the coordinates associated with its columns and rows.

Follow-up: How can the displayed colors be controlled? Set the trace's colorscale; related color-bar attributes can also be configured through colorbar.

QHow is a basic heatmap rendered?

A heatmap can be added as go.Heatmap(...) data in a go.Figure. The resulting figure can then be rendered with fig.show().

Follow-up: What alternative trace is suitable for multichannel image data? The documentation identifies go.Image; for single-channel images, it recommends go.Heatmap.

  • plotly.express.imshow
  • go.Image
  • go.Contour
  • colorscale
  • colorbar

Source: Heatmaps in Python - Plotly. Checked 2026-10-15.