diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 8c247677704a..c2dc1d02463a 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -631,13 +631,16 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): """ - draw a Text instance + Draw a Text instance. """ # local to avoid repeated attribute lookups write = self._pswriter.write if debugPS: write("% text\n") + if len(gc.get_rgb()) == 4 and gc.get_rgb()[3] == 0: + return # Special handling for fully transparent. + if ismath=='TeX': return self.draw_tex(gc, x, y, s, prop, angle) diff --git a/lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf b/lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf new file mode 100644 index 000000000000..80a7f0b2fe39 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf differ diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index fcac2539424c..0d86b32bd9b7 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -12,6 +12,7 @@ import matplotlib import matplotlib.pyplot as plt from matplotlib import patheffects +from matplotlib.testing.decorators import image_comparison from matplotlib.testing.determinism import (_determinism_source_date_epoch, _determinism_check) @@ -148,3 +149,11 @@ def test_determinism_all(): def test_determinism_all_tex(): """Test for reproducible PS/tex output""" _determinism_check(format="ps", usetex=True) + + +@image_comparison(baseline_images=["empty"], extensions=["eps"]) +def test_transparency(): + 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)