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

Skip to content

Commit 0524e4c

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #23964: Fix issue with empty line in ps backend
1 parent 8f39714 commit 0524e4c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
665665
curr_stream[1].append(
666666
(item.x, item.ft_object.get_glyph_name(item.glyph_idx))
667667
)
668-
# append the last entry
669-
stream.append(curr_stream)
668+
# append the last entry if exists
669+
if curr_stream:
670+
stream.append(curr_stream)
670671

671672
self.set_color(*gc.get_rgb())
672673

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ def test_linedash():
254254
assert buf.tell() > 0
255255

256256

257+
def test_empty_line():
258+
# Smoke-test for gh#23954
259+
figure = Figure()
260+
figure.text(0.5, 0.5, "\nfoo\n\n")
261+
buf = io.BytesIO()
262+
figure.savefig(buf, format='eps')
263+
figure.savefig(buf, format='ps')
264+
265+
257266
def test_no_duplicate_definition():
258267

259268
fig = Figure()

0 commit comments

Comments
 (0)