From 79b3e337c5d62a67dce1d4be7690da9dda3cc26a Mon Sep 17 00:00:00 2001 From: Yannic Schroeder Date: Wed, 27 Oct 2021 08:57:52 +0200 Subject: [PATCH] Hide fully transparent latex text in PS output. This problem was fixed before for non-latex text. However, when using latex to render transparent text, it would still show up in PS output. --- lib/matplotlib/backends/backend_ps.py | 3 +++ lib/matplotlib/tests/test_backend_ps.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index c44f89c638d9..35c61b08f26b 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -593,6 +593,9 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms, @_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 " diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 74776fd048a6..50b1b0bc0cbe 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -118,6 +118,16 @@ def test_transparency(): ax.text(.5, .5, "foo", color="r", alpha=0) +@needs_usetex +@image_comparison(["empty.eps"]) +def test_transparency_tex(): + mpl.rcParams['text.usetex'] = True + fig, ax = plt.subplots() + ax.set_axis_off() + ax.plot([0, 1], color="r", alpha=0) + ax.text(.5, .5, "foo", color="r", alpha=0) + + def test_bbox(): fig, ax = plt.subplots() with io.BytesIO() as buf: