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

Skip to content

Commit ee043fc

Browse files
committed
Hide fully transparent text in PS output.
PS doesn't really support transparency (because the format itself doesn't, unless using some nonstandard extensions), but has some special casing for "fully transparent" (see e.g. "rgbFace is None" check in _draw_ps). Also implement the special-casing for text.
1 parent 2296775 commit ee043fc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,16 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
631631

632632
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
633633
"""
634-
draw a Text instance
634+
Draw a Text instance.
635635
"""
636636
# local to avoid repeated attribute lookups
637637
write = self._pswriter.write
638638
if debugPS:
639639
write("% text\n")
640640

641+
if len(gc.get_rgb()) == 4 and gc.get_rgb()[3] == 0:
642+
return # Special handling for fully transparent.
643+
641644
if ismath=='TeX':
642645
return self.draw_tex(gc, x, y, s, prop, angle)
643646

Binary file not shown.

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import matplotlib
1313
import matplotlib.pyplot as plt
1414
from matplotlib import patheffects
15+
from matplotlib.testing.decorators import image_comparison
1516
from matplotlib.testing.determinism import (_determinism_source_date_epoch,
1617
_determinism_check)
1718

@@ -148,3 +149,11 @@ def test_determinism_all():
148149
def test_determinism_all_tex():
149150
"""Test for reproducible PS/tex output"""
150151
_determinism_check(format="ps", usetex=True)
152+
153+
154+
@image_comparison(baseline_images=["empty"], extensions=["eps"])
155+
def test_transparency():
156+
fig, ax = plt.subplots()
157+
ax.set_axis_off()
158+
ax.plot([0, 1], color="r", alpha=0)
159+
ax.text(.5, .5, "foo", color="r", alpha=0)

0 commit comments

Comments
 (0)