-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
tick labels displaced vertically with text.usetex and xcolor #19234
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
Comments
I am able to resolve the issue by undoing the changes made to |
I cannot reproduce using either master or v3.2.2. Do you have a pristine matplotlibrc? |
Can you try clearing
Guess was wrong. |
|
I suspect that we will need to make the logic attn @anntzer |
For completeness the minimal repro case is plt.rcParams.find_all('preamble')
import matplotlib.pyplot as plt
plt.rcParams['text.latex.preamble'] = r'\usepackage[dvipsnames]{xcolor}'
plt.rcParams['text.usetex'] = True
plt.scatter([0, 1, 2, 3], [2,3,1,6])
plt.show() and I can reproduce the bug. |
Thanks for the report. Looks like the following patch fixes the bug, can you confirm? diff --git i/lib/matplotlib/dviread.py w/lib/matplotlib/dviread.py
index 6f65de52b..6b7b52dc1 100644
--- i/lib/matplotlib/dviread.py
+++ w/lib/matplotlib/dviread.py
@@ -313,18 +313,26 @@ class Dvi:
# xxx comment
# down
# push
- # down, down
+ # down
+ # <push, push, xxx, right, xxx, pop, pop> # if using xcolor
+ # down
# push
# down (possibly multiple)
# push <= here, v is the baseline position.
# etc.
# (dviasm is useful to explore this structure.)
+ # Thus, we use the vertical position at the first time the stack depth
+ # reaches 3, while at least three "downs" have been executed, as the
+ # baseline (the "down" count is necessary to handle xcolor).
+ downs = 0
self._baseline_v = None
while True:
byte = self.file.read(1)[0]
self._dtable[byte](self, byte)
+ downs += self._dtable[byte].__name__ == "_down"
if (self._baseline_v is None
- and len(getattr(self, "stack", [])) == 3):
+ and len(getattr(self, "stack", [])) == 3
+ and downs >= 4):
self._baseline_v = self.v
if byte == 140: # end of page
return True |
I can confirm that the patch fixes the issue for me. thanks for the quick response! |
@darthoctopus Would you be interested in opening a PR with that patch and a test? |
Bug report
Tick labels on vertical axes are displaced downwards when
text.usetex
is set to True.Code for reproduction
Actual outcome
Expected outcome
This change happened between 3.2.1 and 3.2.2 (can reproduce in 3.2.2 onwards, inclusive)
Matplotlib version
Matplotlib installed with pip
The text was updated successfully, but these errors were encountered: