8000 Merge pull request #17177 from Xarthisius/issue_17176 · matplotlib/matplotlib@6134ced · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6134ced

Browse files
authored
Merge pull request #17177 from Xarthisius/issue_17176
Manually linewrap PS hexlines. Fixes #17176
2 parents c42e922 + 0f889dc commit 6134ced

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import glob
88
from io import StringIO, TextIOWrapper
99
import logging
10+
import math
1011
import os
1112
import pathlib
1213
import re
1314
import shutil
1415
from tempfile import TemporaryDirectory
15-
import textwrap
1616
import time
1717

1818
import numpy as np
@@ -286,9 +286,17 @@ def draw_image(self, gc, x, y, im, transform=None):
286286
h, w = im.shape[:2]
287287
imagecmd = "false 3 colorimage"
288288
data = im[::-1, :, :3] # Vertically flipped rgb values.
289-
# data.tobytes().hex() has no spaces, so can be linewrapped by relying
290-
# on textwrap.fill breaking long words.
291-
hexlines = textwrap.fill(data.tobytes().hex(), 128)
289+
# data.tobytes().hex() has no spaces, so can be linewrapped by simply
290+
# splitting data every nchars. It's equivalent to textwrap.fill only
291+
# much faster.
292+
nchars = 128
293+
data = data.tobytes().hex()
294+
hexlines = "\n".join(
295+
[
296+
data[n * nchars:(n + 1) * nchars]
297+
for n in range(math.ceil(len(data) / nchars))
298+
]
299+
)
292300

293301
if transform is None:
294302
matrix = "1 0 0 1 0 0"

0 commit comments

Comments
 (0)
0