Authority: Every plot produced in this repository must satisfy the rules in this document. Consistency across 25 chapters depends on strict adherence.
1. Mandatory Setup Block
Copy this verbatim into every notebook that produces plots.
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
2. Color Palette
2.1 Primary Colors (colorblind-safe, Wong 2011)
| Role | Hex | When to use |
|---|---|---|
| Primary | #0077BB | Main curve, first series |
| Secondary | #EE7733 | Second curve, contrast |
| Tertiary | #009988 | Third series |
| Error / negative | #CC3311 | Errors, warnings, losses |
| Neutral | #555555 | Annotations, reference lines |
| Highlight | #EE3377 | Special points, emphasis |
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
2.2 Colormaps by Purpose
| Purpose | Colormap | Usage |
|---|---|---|
| Heatmaps, attention | "viridis" | Attention weight matrices |
| Diverging (signed) | "RdBu_r" | Weight matrices, gradient sign |
| Probability / density | "plasma" | Loss landscapes |
| Categorical (≤ 10 classes) | "tab10" | Class labels |
Forbidden colormaps:
"jet","rainbow","hot"— they distort perception and fail colorblind users. Never encode binary information with red vs. green alone.
3. Required Plot Elements
Every figure must include all of the following:
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
Checklist for every figure:
- Title set with
ax.set_title() - Both axes labelled with
ax.set_xlabel()/ax.set_ylabel() - LaTeX math in labels:
"$\\lambda_i$"(double backslash in Python strings) - Legend present when 2+ series
-
fig.tight_layout()called beforeplt.show() - All colors from
COLORSdict or approved colormaps - No bare
plt.plot()without assigning toax
4. Plot Templates by Type
4.1 Line Plot (curves, training loss, convergence)
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
4.2 Heatmap (matrices, attention, correlation)
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
For seaborn:
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
4.3 Scatter Plot (embeddings, data distributions)
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
4.4 Bar Chart (comparison, ablation results)
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
4.5 Multi-Panel Figure
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
5. Mathematical Concept Conventions
5.1 Vector / Subspace Geometry
- Draw vectors as arrows with
ax.annotate("", xy=tip, xytext=origin, arrowprops=dict(arrowstyle="->", color=..., lw=2)) - Show angles with
matplotlib.patches.Arc - Label vectors with LaTeX:
ax.text(x, y, r"$\mathbf{v}_1$", fontsize=13) - Use
ax.set_aspect("equal")for any geometric figure — distorted axes are errors
5.2 Loss Landscapes
- Use
ax.contourf()for filled contours withcmap="plasma",levels=40 - Overlay gradient descent path with
ax.plot()inCOLORS["error"] - Mark critical points (minima, saddles) with
ax.scatter(),marker="*",s=200
5.3 Probability Distributions
- PDF curves: filled with
ax.fill_between(..., alpha=0.15)+ solid line - Histograms:
ax.hist(..., density=True, bins=40, alpha=0.7)with overlaid PDF - Always label x-axis as the random variable:
"$x$","$z$", etc.
5.4 Training Dynamics
- Use log-scale y-axis for loss:
ax.set_yscale("log") - Mark key events (warmup end, LR drop) with vertical dashed lines:
ax.axvline(step, linestyle="--", color=COLORS["neutral"], label="LR drop")
6. Text and Annotations
Python snippet
Run the code to see stdout, return values, and errors here.
Runs in your browser sandbox. DeepML does not send this code to the server.
7. What Not to Do
| Violation | Correct approach |
|---|---|
plt.plot(x, y) without ax | Always use fig, ax = plt.subplots() |
| No axis labels | Every axis needs a label, always |
| No title | Every figure needs a title |
Default C0, C1 colors | Use COLORS dict |
cmap="jet" | Use "viridis" or "RdBu_r" |
plt.show() before tight_layout | Call fig.tight_layout() first |
| Aspect ratio distortion in geometry | ax.set_aspect("equal") for geometric plots |
| Font size below 11 | Set fontsize ≥ 11 for all text |
| Legend outside figure bounds | Use ax.legend(loc="best") or bbox_to_anchor with bbox_inches="tight" |
Visualization conventions follow the scientific visualization standards of Rougier, Droettboom & Bourne (2014) "Ten Simple Rules for Better Figures" and the colorblind palette of Wong (2011) Nature Methods.