Fix: Vertical Misalignment of LaTeX X-tick Labels#31891
Open
jayaprajapatii wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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(). Sincebaseline_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 fromAxis.draw()after_update_ticks(). For each visible x-tick label1:ascentvialabel._get_layout(renderer).max_ascentacross all labels.(max_ascent - ascent), so all baselines align with the label that has the largest ascent.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