liveBook · Manning

Colormap

As explained in The Well-Grounded Data Analyst

A colormap is a mapping from data values to a range or set of visual colors.

A colormap maps data values to visual colors. Choose one according to whether color should communicate magnitude, direction, or category. section 6.4.2

Use the following categories to match color semantics to the analytical question:

  • Sequential colormaps change lightness gradually for continuous measurements; darker tones indicate larger values. section 6.4.2
  • Diverging colormaps use hue for direction and lightness for strength, such as red for negative values and blue for positive values. section 6.4.2
  • Categorical colormaps assign distinct colors for visual separation; colors do not represent numerical order. section 6.4.2

Survey heatmap

A normalized survey crosstab can use the grayscale sequential colormap with vmin=0 and vmax=1. Cell annotations show proportions, while darker cells indicate more respondents. 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 seaborn heatmap that applies a sequential grayscale colormap, fixed bounds, square cells, and annotations. section 6.4.2

How The Well-Grounded Data Analyst covers it

How deep it goes
Defines sequential, diverging, and categorical choices with examples, then demonstrates a normalized heatmap; it stops short of color theory.
Examples
Demonstrates grayscale survey heatmaps, red-blue diverging values, and distinct colors for pie-chart slices or bars.
What it assumes
Assumes a table of measurements or categories and distinguishes continuous magnitude, directional values, and nominal groups.
What you can do after
Apply colormaps via seaborn heatmaps by matching sequential, diverging, or categorical encoding to the data meaning.
How it connects
Connects colormaps with heatmaps, crosstabs, categorical data, continuous scales, and data visualization.

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.