8000 Manually linewrap PS hexlines. Fixes #17176 · matplotlib/matplotlib@0f889dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f889dc

Browse files
committed
Manually linewrap PS hexlines. Fixes #17176
1 parent 8e2f715 commit 0f889dc

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