Use 3D carefully
3D plots can look impressive but are often harder to interpret than they seem — a screen is 2D, so any 3D chart is really a projection, and projections distort distance and depth judgment. Two points that look close together might be far apart along the axis pointing "into" the screen.
Use 3D when:
- You genuinely need three continuous numeric variables plotted together
- Interaction (rotate/zoom) helps understanding, and the reader will actually rotate it
- Two 2D scatter plots (or a bubble chart) can't tell the same story
If you just want to add a third variable to a 2D scatter, prefer color or bubble size (see the previous two pages) — it's usually clearer than forcing a third spatial axis.
Example
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"x": [1, 2, 3, 4, 5],
"y": [10, 6, 8, 4, 7],
"z": [100, 120, 90, 150, 110],
"group": ["A", "A", "B", "B", "A"],
})
fig = px.scatter_3d(df, x="x", y="y", z="z", color="group", title="3D scatter")
fig.show()In the rendered chart, dragging rotates the camera and scrolling zooms — that interactivity is what makes a 3D plot usable at all; a static screenshot of the same figure often hides more than it reveals.
Tips
- Rotate before you conclude anything — a single static angle can hide clusters or trends.
- Prefer
scatter_3donly when a 2D-plus-color/size chart genuinely loses information. - Heavy point counts get cluttered fast in 3D; consider sampling or aggregating first.
flowchart TD
A["Need to show 3 numeric variables"] --> B{"Can color or bubble size
carry the 3rd variable?"}
B -- "Yes" --> C["Use 2D scatter/bubble chart
(easier to read, no rotation needed)"]
B -- "No, spatial depth matters" --> D["Use scatter_3d
and expect the reader to rotate it"]
Check your understanding
Which function draws the 3D scatter plot in the lesson?
px.scatter_3d takes x, y and z columns, with color for an optional group.
Show answer
A — px.scatter_3d — px.scatter_3d takes x, y and z columns, with color for an optional group.
When does the lesson say 3D is justified?
A screen is 2D, so a 3D chart is a projection that distorts distance. Prefer color or bubble size for a third variable when possible.
Show answer
B — You genuinely need three continuous variables and rotating helps, and 2D charts cannot tell the same story — A screen is 2D, so a 3D chart is a projection that distorts distance. Prefer color or bubble size for a third variable when possible.
Why should you rotate a 3D scatter before drawing conclusions?
Any one camera angle can accidentally hide a cluster or trend, which is why interactivity matters.
Show answer
B — A single static angle can hide clusters behind other points — Any one camera angle can accidentally hide a cluster or trend, which is why interactivity matters.
Your 3D chart has far too many points and is cluttered. What does the lesson suggest?
Heavy point counts get cluttered fast in 3D, so sample or aggregate.
Show answer
D — Sample or aggregate first — Heavy point counts get cluttered fast in 3D, so sample or aggregate.
Next
Continue to: Creating Dashboards with Plotly to combine multiple charts into one view.
🧪 Try It Yourself
Exercise 1 – Build a 3D Scatter
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Color the Third Group
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – When to Avoid 3D
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.