GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix: Vertical Misalignment of LaTeX X-tick Labels by jayaprajapatii · Pull Request #31891 · matplotlib/matplotlib

Conversation

@jayaprajapatii

@jayaprajapatii jayaprajapatii commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

closes #31802

PR Summary

x-tick labels using LaTeX/mathtext were vertically misaligned when savefig(dpi=300) was used, specifically when labels had different "ascents" (height above baseline) due to differing mathtext content — e.g. $w^{(2)}_1$ (superscript + subscript) vs $b^{(2)}$ (superscript only).

Why is this change necessary?

All x-tick label1s are top-aligned (va='top') to the same y-position via _get_text1_transform(). Since baseline_y = y1 - ascent, labels with different ascents end up with different baseline positions even though their top edges align. This difference is small but becomes visually noticeable at high DPI.

What problem does it solve?

It fixes the vertical misalignment of LaTeX x-tick labels, where one label (with a smaller ascent) appeared visually higher than the others.

Reason for this implementation?

Added Axis._align_xtick_label_baselines(), called from Axis.draw() after _update_ticks(). For each visible x-tick label1:

  1. Measure its ascent via label._get_layout(renderer).
  2. Find max_ascent across all labels.
  3. Shift labels with smaller ascent down by (max_ascent - ascent), so all baselines align with the label that has the largest ascent.
  4. Added Regression test.

NOTE: A 0.5px threshold skips labels whose ascent differs only by sub-pixel amounts, so plain numeric/text tick labels (where this difference is negligible) remain unaffected.

AI Disclosure

AI was used in documentation build and suggesting validation scenarios.
All Implementation, testing, and verification were done manually.

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jayaprajapatii
Fix vertical misalignment of x-tick labels
1845e66
@github-actions github-actions Bot added the topic: ticks axis labels label Jun 14, 2026

This branch has not been deployed

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic: ticks axis labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: LaTeX X-Tick Labels are Vertically Misaligned When DPI is Set

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jayaprajapatii
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.