Sub topic 9
Plotting the map clearly
You already have brand coordinates from PCA or MDS. This chapter covers turning those numbers into a chart that a stakeholder can read without distorting what the data says. It assumes you can run the PCA example from the ratings chapter and use basic matplotlib. It also assumes you know that axis meaning comes from loadings, which the axis-interpretation chapter covers.
A plotting mistake is not cosmetic. If the axes are stretched, distances on the page no longer match distances in the data, and every conclusion about crowding or white space is affected.
What the plot has to communicate
A perceptual map makes one claim: closer brands are seen as more similar. The plot should carry that claim without adding others. Most of the choices below follow from that.
| Design choice | Why it matters | Default to use |
|---|---|---|
| Aspect ratio | Unequal scaling makes distances lie | Equal units on both axes |
| Axis labels | Readers need to know what each direction means | Name plus variance explained |
| Zero lines | Mark the market average, since scores are centered | Thin grey lines |
| Brand labels | A dot with no name is useless | Direct labels, no legend |
| Attribute arrows | Show which attributes drive each direction | Optional, drawn from the origin |
| Tick values | Coordinates are abstract and often confuse readers | Hide or de-emphasize |
Keep the scale equal
PCA coordinates are in the same units on both axes. matplotlib does not know that, and it fills the figure box with whatever aspect ratio the window has. If dimension 1 spans 6 units and dimension 2 spans 2, a wide box stretches the second dimension and makes brands look further apart vertically than they are.
Call ax.set_aspect("equal", adjustable="datalim"). Then one unit along x has the same length on the page as one unit along y, and visual distance is proportional to data distance. The same applies to MDS maps, where distance is the whole point.
A square figure (figsize=(7, 7)) pairs well with equal aspect, because a wide figure with equal scaling leaves large empty margins.
Label the axes honestly
Two rules apply to axis labels.
- Do not label an axis "Dimension 1" in the final deliverable. Use the name you derived from the loadings, for example "Value-oriented to premium". Keep the generic name in your working notebook.
- Put the variance explained in the label, for example "(54% of variance)". This tells readers how much of the original data each axis keeps. If the two axes together explain 60%, the map leaves out 40% of the pattern, and readers should see that.
For MDS there are no loadings and no variance ratio. Name axes only if you have validated them by regressing attribute ratings onto the configuration. Otherwise label them neutrally, and report stress in a caption or footnote.
Label brands directly
Use text next to each point and skip the legend. A legend forces the eye to go back and forth. Use an offset in points (xytext=(6, 6)), not in data units, so the gap between a dot and its label stays the same whatever the axis range.
Labels collide when brands sit close together. These are the options, in order of effort:
- Increase figure size or font size consistently, then nudge individual labels by hand with a per-brand offset dictionary.
- Use the
adjustTextpackage, which moves labels to reduce overlap and draws leader lines. It is a third-party install (pip install adjustText). - If two brands overlap almost exactly, say so in the text. That near-overlap is itself a finding about crowding.
Add attribute arrows when they help
A plot with brands only tells you who is near whom. A plot that also shows attribute directions, called a biplot, tells you why. Each arrow runs from the origin toward the loading of one attribute. A brand lying far along an arrow's direction scores high on that attribute.
Loadings and brand coordinates have different scales, so you must rescale the arrows to fit the plot. This rescaling changes only arrow length. The direction of each arrow is what carries information, and the arrow length should be read only relative to the other arrows. Mention this in a caption so no one reads arrow length as an absolute effect size.
A complete plotting script
This script is self-contained. It rebuilds the PCA from the ratings chapter, fixes the sign of each axis, and draws the map with equal scaling, variance in the axis labels, brand labels, and attribute arrows.
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
ratings = pd.DataFrame(
{
"affordable": [6.1, 5.4, 2.3, 3.0, 4.2],
"premium": [2.0, 3.1, 6.4, 5.8, 4.0],
"innovative": [3.2, 5.9, 5.1, 2.5, 4.4],
"reliable": [5.0, 3.3, 5.6, 6.0, 4.1],
},
index=["Brand A", "Brand B", "Brand C", "Brand D", "Brand E"],
)
scaled = StandardScaler().fit_transform(ratings)
pca = PCA(n_components=2)
coords = pd.DataFrame(
pca.fit_transform(scaled), index=ratings.index, columns=["dim1", "dim2"]
)
loadings = pd.DataFrame(
pca.components_.T, index=ratings.columns, columns=["dim1", "dim2"]
)
ratio = pca.explained_variance_ratio_
def orient(dim, attr):
"""Flip a dimension so the chosen attribute points in the positive direction."""
if loadings.loc[attr, dim] < 0:
coords[dim] = -coords[dim]
loadings[dim] = -loadings[dim]
orient("dim1", "premium") # premium to the right
orient("dim2", "innovative") # innovative upward
fig, ax = plt.subplots(figsize=(7, 7))
ax.scatter(coords["dim1"], coords["dim2"], s=70, color="tab:blue", zorder=3)
for brand, row in coords.iterrows():
ax.annotate(
brand,
(row["dim1"], row["dim2"]),
xytext=(6, 6),
textcoords="offset points",
zorder=4,
)
# Rescale loadings so the longest arrow reaches about 80% of the brand spread.
k = 0.8 * coords.abs().to_numpy().max() / loadings.abs().to_numpy().max()
for attr, row in loadings.iterrows():
x, y = row["dim1"] * k, row["dim2"] * k
ax.annotate(
"",
xy=(x, y),
xytext=(0, 0),
arrowprops={"arrowstyle": "->", "color": "tab:red", "alpha": 0.7},
)
ax.text(x * 1.1, y * 1.1, attr, color="tab:red", ha="center", va="center")
ax.axhline(0, color="grey", linewidth=0.8, zorder=1)
ax.axvline(0, color="grey", linewidth=0.8, zorder=1)
ax.set_aspect("equal", adjustable="datalim")
ax.margins(0.15)
ax.set_xlabel(f"Value to premium ({ratio[0]:.0%} of variance)")
ax.set_ylabel(f"Established to innovative ({ratio[1]:.0%} of variance)")
ax.set_title("Perceptual map of five brands")
ax.tick_params(labelbottom=False, labelleft=False)
fig.savefig("perceptual_map.png", dpi=200, bbox_inches="tight")
plt.show()The axis names in this script ("Value to premium", "Established to innovative") are placeholders. Check them against your own loadings table before you publish. If your loadings tell a different story, change the names.
Signs and rotations are arbitrary
PCA fixes each axis only up to a sign. Running the same code on slightly different data can mirror the map left to right. MDS has the same problem and more: any rotation or reflection of the configuration is equally valid, because only distances matter.
This causes two practical problems.
- Two maps built at different times may look unrelated when they are the same map flipped. The
orientfunction above fixes this by tying each direction to a named attribute, so the premium side is always on the right. - Stakeholders may read "right" as "better". Do not let them. Neither direction is better unless the axis name says so.
For MDS maps, anchor orientation by hand: reflect or rotate the configuration so that a reference brand sits in a consistent place. Rotating by a fixed angle changes no distances.
Common errors
- Letting the figure box set the aspect ratio. A stretched plot misstates distances. Always set equal aspect.
- Plotting more than two dimensions on two axes. If you fitted three components, a 2D plot drops one. Say what was dropped, or draw a second plot of dimensions 1 and 3.
- Reading the origin as a brand. The origin is the average of all mapped brands. A brand near the center is average on both dimensions, not neutral or unpositioned.
- Using color for meaning that is not in the data. If you color points by price tier or company, add a short key and check it works in grayscale.
- Drawing density or cluster shapes by eye. Shaded regions imply a clustering result. If you add them, base them on an actual method and state it.
- Publishing tick numbers. Coordinates are in standardized units with no business meaning. Hiding them directs attention to the relative positions.
Exporting for reports
Save at 200 dpi or more for slides and documents, and use bbox_inches="tight" so labels are not clipped at the edge. For documents that will be resized, save an SVG or PDF as well (fig.savefig("perceptual_map.svg")), because vector files stay sharp at any size.
Always put these three items in the caption or notes: the sample size and survey date, the variance explained (PCA) or the stress value (MDS), and a one-line note that distance reflects perceived similarity, not sales or quality.
Exercises
Exercise
You plot a PCA map with default matplotlib settings in a wide 12 x 4 inch figure. Brands A and B are 1 unit apart horizontally and 1 unit apart vertically in the data, but on the page they look 3 times further apart vertically. What went wrong, and what is the fix?
Show answer
The axes are not scaled equally. matplotlib fitted the data to the wide box, so one data unit covers a different page length on each axis. Call ax.set_aspect("equal", adjustable="datalim") and use a roughly square figure so that equal data distances look equal.
Exercise
Next quarter's survey is re-run and the new map looks like a left-right mirror image of last quarter's. Brand positions relative to each other are unchanged. Explain why this happened and how to prevent it.
Show answer
PCA and MDS fix axes only up to sign, reflection, and (for MDS) rotation, so the mirror image carries the same distances. Prevent it by orienting each axis with a named attribute, for example flipping dimension 1 so that the "premium" loading is always positive, and by anchoring MDS maps to a reference brand. Then maps from different periods are comparable.