Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Inconsistent rendering between backends when rendering Mathtext horizontal rule #23763

Open
tfpf opened this issue Aug 28, 2022 · 0 comments · May be fixed by #26337
Open

[Bug]: Inconsistent rendering between backends when rendering Mathtext horizontal rule #23763

tfpf opened this issue Aug 28, 2022 · 0 comments · May be fixed by #26337

Comments

@tfpf
Copy link
Contributor

tfpf commented Aug 28, 2022

Bug summary

When the last item in a Mathtext Vlist is an Hrule, the AGG and SVG backends render the image differently. The difference is not obvious at small font sizes.

To see this happen, we have to dive into Mathtext internals. An easy way is to modify fractions to end with the horizontal rule.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib._mathtext as _mathtext

plt.rcdefaults()

def _genfrac(self, ldelim, rdelim, rule, style, num, den):
    state = self.get_state()
    thickness = state.get_current_underline_thickness()
    vlist = _mathtext.Vlist([num, _mathtext.Vbox(0, 2 * thickness), _mathtext.Hrule(state, thickness)])
    return [_mathtext.Hlist([vlist])]
_mathtext.Parser._genfrac = _genfrac


(fig, ax) = plt.subplots()
plt.text(.5, .3, r'$\dfrac{up}{down}$', size=100, ha='center', va='baseline')
plt.axhline(.3)
plt.savefig('Hrule_at_bottom.png')
plt.savefig('Hrule_at_bottom.svg')
plt.show()

Actual outcome

Hrule_at_bottom
PNG output

Hrule_at_bottom
SVG output

Expected outcome

Both images should be identical.

Additional information

Why does it matter if it's related to a private module in Matplotlib?

This is one of the things holding up #23616. Vlists ending with an Hrule are not being positioned correctly.

Operating system

Ubuntu 20.04 LTS Focal Fossa on WSL

Matplotlib Version

3.5.0.dev5855+gee2f68bdc9

Matplotlib Backend

WXAgg

Python version

Python 3.8.10

Jupyter version

6.0.3

Installation

git checkout

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

Successfully merging a pull request may close this issue.

2 participants