Skip to content

Match Matplotlib gallery text fidelity [mpl compatibility]#255

Draft
sselvakumaran wants to merge 3 commits into
agent/gallery-compat-pie-text-vectorfrom
agent/matplotlib-text-fidelity
Draft

Match Matplotlib gallery text fidelity [mpl compatibility]#255
sselvakumaran wants to merge 3 commits into
agent/gallery-compat-pie-text-vectorfrom
agent/matplotlib-text-fidelity

Conversation

@sselvakumaran

@sselvakumaran sselvakumaran commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This follow-up is stacked on #243 and fixes the remaining text fidelity gaps in two official Matplotlib 3.11 gallery examples:

  • honors fontdict family, color, weight, style, and size for axes titles and labels across browser, SVG, and native PNG paths
  • converts supported mathtext named functions (\cos, \exp, etc.) to upright readable text while preserving italic variables, Unicode π, and the Matplotlib minus sign
  • adds the exact ö and ü glyphs used by text_commands.py to the bounded native atlas, without changing unrelated historical advances

Exact gallery comparisons

text_commands.py

Matplotlib 3.11 reference → #243 tip → this follow-up. The detail crop makes the restored für Festkörperphysik glyphs visible.

text_commands Matplotlib reference, before, and after

text_fontdict.py

Matplotlib 3.11 reference → #243 tip → this follow-up. The follow-up restores the dark-red 16 pt title/axis styling and renders cos(2πt)exp(−t) instead of leaking TeX commands.

text_fontdict Matplotlib reference, before, and after

Verification

  • pnpm run typecheck
  • pnpm run build
  • focused Python compatibility/export suite: 137 passed
  • full Python suite: 2,055 passed, 118 skipped; four sandbox/PATH-only failures rerun individually with the required Node/loopback/Chromium access and passed
  • Rust: 115 passed
  • Ruff check and format check: passed
  • full official in-scope Matplotlib 3.11 audit: 88 examples executed; both targeted examples render, and text_commands.py remains automatically classified as similar

Draft because this intentionally depends on #243; it should be rebased/retargeted after that PR lands.

Summary by CodeRabbit

  • New Features

    • Added support for configurable title and axis-label fonts, including family, style, weight, size, and color.
    • Improved math text rendering, including named functions, spacing, Unicode minus signs, and italic styling.
    • Added native rendering support for ö and ü characters in raster and SVG output.
  • Bug Fixes

    • Improved consistency of text styling across chart output formats.
    • Stabilized select font metrics for reliable rendering.
  • Documentation

    • Updated native text coverage documentation.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Chart text styling now propagates through pyplot, chart styles, SVG, raster, and DOM renderers. Mathtext conversion reports italic ranges and supports more commands. Native font data adds ö and ü coverage with updated generation, documentation, and tests.

Changes

Text rendering updates

Layer / File(s) Summary
Text style propagation
python/xy/styles.py, python/xy/pyplot/_axes.py
Axis font properties are validated and pyplot title, axis-label, and chrome styles are normalized and merged into chart styles.
Mathtext conversion and italic ranges
python/xy/pyplot/_mathtext.py, python/xy/pyplot/_axes.py
Mathtext conversion recognizes additional upright commands, normalizes spacing and minus signs, and exposes italic character ranges.
Renderer typography application
python/xy/_svg.py, python/xy/_raster.py, js/src/50_chartview.ts
SVG, raster, and DOM rendering apply configured title and axis font family, style, weight, size, color, and emphasis.
Native umlaut glyph coverage
scripts/gen_font.py, src/font.rs, src/raster.rs, spec/api/styling.md, spec/design/rust-engine.md
Generated and baked font data includes ö and ü, stabilizes selected advances, and documents and tests the expanded coverage.
Text rendering regression tests
tests/pyplot/test_gallery_text_pie_compat.py
Regression tests verify styled titles and labels, named math functions, italic ranges, and umlaut output in PNG and SVG.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Axes
  participant Chart
  participant SVG
  participant Raster
  Axes->>Chart: pass title and axis styles
  Chart->>SVG: render styled text
  Chart->>Raster: render styled text
  SVG-->>Axes: return SVG output
  Raster-->>Axes: return raster output
Loading

Suggested reviewers: farhanaliraza, alek99

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main goal: improving Matplotlib gallery text fidelity and compatibility.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/matplotlib-text-fidelity

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Visual proof for the exact official Matplotlib 3.11 text_commands.py case (reference → #243 tip → this follow-up):

text_commands Matplotlib reference, before, and after

The follow-up restores the missing ü and ö in für Festkörperphysik; the full-size detail crop is included in the image. The PR description also includes the text_fontdict.py reference/before/after comparison.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

The Comment image shows a three-column text_commands.py comparison: “Matplotlib 3.11 reference”, “Before: #243 tip”, and “After: this follow-up.” In the middle panel, the Unicode label incorrectly reads Institut fr Festkrperphysik; the after panel restores Institut für Festkörperphysik. The lower detail crop also shows the restored accented glyphs alongside the reference. It additionally shows that the prior rendering was lighter/gray compared with the reference.

The PR description image shows the analogous text_fontdict.py comparison. The before panel leaks the math commands as \cos(2 pi t) \exp(-t) and loses the dark-red serif title and label styling, whereas the after panel displays readable cos(2πt)exp(−t) with restored dark-red fontdict styling.

@sselvakumaran, thanks—the visual comparisons clearly identify the targeted regressions and their intended fidelity. I’ll review the complete change set with these reference outputs in mind.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codspeed-hq

codspeed-hq Bot commented Jul 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 102 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing agent/matplotlib-text-fidelity (7f1899a) with agent/gallery-compat-pie-text-vector (2946fc6)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@spec/design/rust-engine.md`:
- Around line 130-136: Update the earlier font.rs description to report 207
glyph records and 112 non-ASCII codepoints, matching the §2 module-boundary
counts and current font::EXTRA_CODEPOINTS contents. If the referenced font.rs
line count has changed, update the “font.rs (1039)” figure as well; modify only
the stale specification references.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c781469f-ff49-41db-9730-ed566ecbf587

📥 Commits

Reviewing files that changed from the base of the PR and between 2946fc6 and 7f1899a.

📒 Files selected for processing (12)
  • js/src/50_chartview.ts
  • python/xy/_raster.py
  • python/xy/_svg.py
  • python/xy/pyplot/_axes.py
  • python/xy/pyplot/_mathtext.py
  • python/xy/styles.py
  • scripts/gen_font.py
  • spec/api/styling.md
  • spec/design/rust-engine.md
  • src/font.rs
  • src/raster.rs
  • tests/pyplot/test_gallery_text_pie_compat.py

Comment on lines +130 to +136
Unicode coverage. `font.rs` bakes exactly 207 glyphs: ASCII 32–126 (95) plus
the 112 codepoints enumerated in `font::EXTRA_CODEPOINTS` — lowercase Greek
(α–ω) and the eleven uppercase Greek letters that differ from Latin forms
(Γ Δ Θ Λ Ξ Π Σ Υ Φ Ψ Ω), math operators (`∂ ∇ ∈ − ∓ √ ∝ ∞ ∫ ≈ ≠ ≤ ≥`), the
left and right arrows only, super/subscript digits and a handful of subscript
letters, typographic quotes, en/em dashes, and a few symbols (`° ± × · µ ²³¹ …`).
Nothing else exists: no accented Latin at all, no Cyrillic, no CJK, no Arabic,
letters, typographic quotes, en/em dashes, the `ö`/`ü` glyphs used by
Matplotlib's canonical text example, and a few symbols (`° ± × · µ ²³¹ …`).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Sync the stale glyph counts in §2 module boundaries. This section now correctly says 207 glyphs / 112 codepoints, but the font.rs description earlier in the same file still reads "205 glyph records" and "the 110 non-ASCII codepoints" — now inconsistent with font.rs and this section. Update those two figures (and the font.rs (1039) line count if it also moved) so the spec stays current.

As per path instructions: "keep the entire spec/ directory current with relevant code, configuration, build, and release changes."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/design/rust-engine.md` around lines 130 - 136, Update the earlier
font.rs description to report 207 glyph records and 112 non-ASCII codepoints,
matching the §2 module-boundary counts and current font::EXTRA_CODEPOINTS
contents. If the referenced font.rs line count has changed, update the “font.rs
(1039)” figure as well; modify only the stale specification references.

Source: Path instructions

@sselvakumaran sselvakumaran changed the title Match Matplotlib gallery text fidelity Match Matplotlib gallery text fidelity [mpl compatibility] Jul 24, 2026
@sselvakumaran

Copy link
Copy Markdown
Contributor Author

this should probably also allow bold, etc. to the subtitle. (might be fixed in another PR)
as well the labels on the left for ticks are cut off (hopefully should be fixed by #256)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant