Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Eqnarray in AnchoredText results in misplaced text (new in v3.6.0) #23977

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

Closed
BogdanRajkov opened this issue Sep 21, 2022 · 4 comments · May be fixed by #24011
Closed

[Bug]: Eqnarray in AnchoredText results in misplaced text (new in v3.6.0) #23977

BogdanRajkov opened this issue Sep 21, 2022 · 4 comments · May be fixed by #24011

Comments

@BogdanRajkov
Copy link

BogdanRajkov commented Sep 21, 2022

Bug summary

The title pretty much sums it up. I have no idea if this only happens for the eqnarray environment and AnchoredText or for all Latex text and other boxes, e.g. legends, but also don't have the time to test it myself. I'll simply keep using v3.5.3, but I hope this helps other people get to the root cause.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.offsetbox import AnchoredText

v = matplotlib.__version__
fig, ax = plt.subplots()
x = np.linspace(0, 2*np.pi)
y = np.sin(x)
plt.plot(x, y)

text = ('\\begin{eqnarray*}'
        f'foo \\\\'
        f'{v=} \\\\'
        '\\end{eqnarray*}')
at = AnchoredText(text, loc='upper left', prop={'usetex': True})
# at = AnchoredText(text, loc='upper left')
ax.add_artist(at)
plt.show()

Actual outcome

new_behaviour

Expected outcome

old_behaviour

Additional information

I should mention that when usetex is set to False, the text is displayed just fine (by text I mean the code, obviously it doesn't compile), so I can narrow it down at least that much.

Operating system

Windows 11

Matplotlib Version

3.6.0

Matplotlib Backend

QtAgg

Python version

Python 3.10.1

Jupyter version

No response

Installation

pip

@dstansby
Copy link
Member

Looking into this now - bisects to c973552

@dstansby
Copy link
Member

Had a quick look and can't work out what the fix is - perhaps @anntzer will have more luck as you wrote the failing commit.

@anntzer
Copy link
Contributor

anntzer commented Sep 23, 2022

I can confirm the issue and repro it even more simply with e.g.

import matplotlib.pyplot as plt
plt.text(.5, .5, r'$$E = mc^2$$', usetex=True)
plt.axvline(.5)
plt.axhline(.5)
plt.show()

the basic problem being that we don't get a baseline mark at the baseline of the last line of displaymath mode, but only at the baseline of the (empty) following paragraph.

Probably there's some solution which involves fiddling with TeX internals (and I still think the general approach is the correct one), but it doesn't look obvious to fix, so possibly in the short term #22360 should be reverted for now and thus also #22361 (first), and #22350 (which was the original issue that triggered these changes) reopened. Apologies for the disruption.

@anntzer anntzer changed the title [Bug]: Eqnarray in AchoredText results in misplaced text (new in v3.6.0) [Bug]: Eqnarray in AnchoredText results in misplaced text (new in v3.6.0) Sep 28, 2022
@QuLogic
Copy link
Member

QuLogic commented Oct 6, 2022

Should be fixed by the revert in #24047.

@QuLogic QuLogic closed this as completed Oct 6, 2022
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.

5 participants