liveBook · Manning

Heat map

As explained in The Well-Grounded Data Analyst

A heatmap is a visualization that encodes values in a matrix or table with varying color intensity.

A heatmap turns a matrix or table into a visual pattern by encoding values with color intensity. It helps reveal differences without staring at tables of numbers. section 6.4.2

Use a heatmap when:

  • A crosstab compares two categorical variables, such as AI-tool usage and sentiment. section 6.4.2
  • Sequential colormaps represent magnitude through lightness; darker cells indicate larger values. section 6.4.2
  • Normalization makes row or column proportions comparable, while annotations display the values directly. section 6.4.2

Survey favorability

Filter out respondents for whom the follow-up question does not apply, create a row-normalized pandas crosstab, and render it with seaborn using a grayscale scale from 0 to 1. The resulting cells compare how favorably AI users and aspiring users view AI tools. section 6.4.2

fig, axis = plt.subplots()

sns.heatmap(
    data=pd.crosstab(
        index=survey.loc[survey["AISelect"]
 != "No, and I don't plan to", "AISelect"],
        columns=survey.loc[survey["AISelect"]
 != "No, and I don't plan to", "AISent"],
        normalize="index"
    ),
    cmap="Greys",
    vmin=0,
    vmax=1,
    square=True,
    annot=True,
    ax=axis
)

fig.suptitle("How favorably do different people view AI tools?")

axis.set(
    xlabel="How favorable is your stance on using AI tools?",
    ylabel="Do you currently use AI tools?"
)

plt.show()

Inspect a complete implementation combining filtering, crosstab normalization, color scaling, square cells, annotations, and labels. section 6.4.2

How The Well-Grounded Data Analyst covers it

How deep it goes
Explains sequential, diverging, and categorical colormaps and demonstrates normalized annotated heatmaps, but does not develop visualization theory.
Examples
Uses AI-tool sentiment, trust, use cases, and job roles as survey dimensions for heatmap comparisons.
What it assumes
Assumes pandas tables and categorical variables, while demonstrating crosstabs and color-scale choices through survey analysis.
What you can do after
Build heatmaps with pandas crosstabs and seaborn, choosing normalization, scales, annotations, and labels for stakeholder comparisons.
How it connects
Connects heatmaps to crosstabs, categorical data, normalization, pandas, seaborn, and colormaps.

Also explained in

Compare how 7 books explain heat map →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.