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






