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]: EPS export shows hidden tick labels when using tex for text rendering #21466

Closed
yschroeder opened this issue Oct 26, 2021 · 5 comments · Fixed by #21470
Closed

[Bug]: EPS export shows hidden tick labels when using tex for text rendering #21466

yschroeder opened this issue Oct 26, 2021 · 5 comments · Fixed by #21470
Milestone

Comments

@yschroeder
Copy link
Contributor

Bug summary

When setting text.usetex: True, the EPS export produces spurious axis labels which are not visible in the PDF export.

This seems somewhat similar to #10163.

Code for reproduction

import matplotlib.pyplot as plt

# using tex shows spurious labels on the x axis
plt.rcParams.update({"text.usetex": True})

fig, axs = plt.subplots(1, 3, sharey=True)

# add a big axes, hide frame
hidden_ax = fig.add_subplot(111, frameon=False)

# hide tick and tick label of the big axes
plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False)

# comment in this workaround
# as suggested in https://github.com/matplotlib/matplotlib/issues/10163/
# hidden_ax.xaxis.set_major_locator(plt.NullLocator())
# hidden_ax.yaxis.set_major_locator(plt.NullLocator())

# save figures
fig.savefig("test.eps")
fig.savefig("test.pdf")

Actual outcome

broken_eps

Expected outcome

working_pdf

Operating system

Arch

Matplotlib Version

3.4.3

Matplotlib Backend

Qt5Agg

Python version

3.9.7

Jupyter version

No response

Other libraries

texlive-core 2021.58710-2
texlive-bin 2021.58686-3

Installation

Linux package manager (Debian/Fedora/etc.)

Conda channel

No response

@anntzer
Copy link
Contributor

anntzer commented Oct 26, 2021

Looks like the same fix as in #10166 applies, i.e.

diff --git i/lib/matplotlib/backends/backend_ps.py w/lib/matplotlib/backends/backend_ps.py
index c44f89c638..35c61b08f2 100644
--- i/lib/matplotlib/backends/backend_ps.py
+++ w/lib/matplotlib/backends/backend_ps.py
@@ -593,6 +593,9 @@ translate
     @_log_if_debug_on
     def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
         # docstring inherited
+        if self._is_transparent(gc.get_rgb()):
+            return  # Special handling for fully transparent.
+
         if not hasattr(self, "psfrag"):
             self._logwarn_once(
                 "The PS backend determines usetex status solely based on "

seems to fix the problem?

Probably the test_transparency intrroduced in #10166 could be parametrized to also test the usetex=True case.

@anntzer anntzer added the status: has patch patch suggested, PR still needed label Oct 26, 2021
@yschroeder
Copy link
Contributor Author

I looked at #10166 yesterday and also had the hunch that your proposed check is missing in the draw_tex() function. However I was still in the process of setting up a matplotlib development environment, you were faster with the patch 😄

I have the dev environment set up now and can confirm that test_transparency() exposes the bug by adding plt.rcParams.update({"text.usetex": True}) as the first line in that test. By adding your patch to the PS backend, the modified test that exposed the bug is green again.

I can further confirm that my original problem is solved as well by the patch.

So overall, your patch fixes the problem and a modified version of test_transparency() is able to avoid a regression.

Will you prepare a PR for this?

@QuLogic
Copy link
Member

QuLogic commented Oct 27, 2021

Usually when @anntzer adds that label, it's because he hasn't the time to do the full PR with tests/docs/etc. So feel free to open one yourself.

@yschroeder
Copy link
Contributor Author

OK, I went ahead and created a PR.

@jklymak
Copy link
Member

jklymak commented Oct 27, 2021

Closed by #21470

@jklymak jklymak closed this as completed Oct 27, 2021
@jklymak jklymak added this to the v3.5.0 milestone Oct 27, 2021
@QuLogic QuLogic removed the status: has patch patch suggested, PR still needed label Oct 27, 2021
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.

4 participants