2
2
A PostScript backend, which can produce both PostScript .ps and .eps.
3
3
"""
4
4
5
- import binascii
6
5
import datetime
7
6
import glob
8
7
from io import StringIO , TextIOWrapper
13
12
import shutil
14
13
import subprocess
15
14
from tempfile import TemporaryDirectory
15
+ import textwrap
16
16
import time
17
17
18
18
import numpy as np
@@ -392,20 +392,6 @@ def _get_font_ttf(self, prop):
392
392
font .set_size (size , 72.0 )
393
393
return font
394
394
395
- def _rgb (self , rgba ):
396
- h , w = rgba .shape [:2 ]
397
- rgb = rgba [::- 1 , :, :3 ]
398
- return h , w , rgb .tostring ()
399
-
400
- def _hex_lines (self , s , chars_per_line = 128 ):
401
- s = binascii .b2a_hex (s )
402
- nhex = len (s )
403
- lines = []
404
- for i in range (0 , nhex , chars_per_line ):
405
- limit = min (i + chars_per_line , nhex )
406
- lines .append (s [i :limit ])
407
- return lines
408
-
409
395
def get_image_magnification (self ):
410
396
"""
411
397
Get the factor by which to magnify images passed to draw_image.
@@ -422,17 +408,15 @@ def option_image_nocomposite(self):
422
408
# docstring inherited
423
409
return not rcParams ['image.composite_image' ]
424
410
425
- def _get_image_h_w_bits_command (self , im ):
426
- h , w , bits = self ._rgb (im )
427
- imagecmd = "false 3 colorimage"
428
-
429
- return h , w , bits , imagecmd
430
-
431
411
def draw_image (self , gc , x , y , im , transform = None ):
432
412
# docstring inherited
433
413
434
- h , w , bits , imagecmd = self ._get_image_h_w_bits_command (im )
435
- hexlines = b'\n ' .join (self ._hex_lines (bits )).decode ('ascii' )
414
+ h , w = im .shape [:2 ]
415
+ imagecmd = "false 3 colorimage"
416
+ data = im [::- 1 , :, :3 ] # Vertically flipped rgb values.
417
+ # data.tobytes().hex() has no spaces, so can be linewrapped by relying
418
+ # on textwrap.fill breaking long words.
419
+ hexlines = textwrap .fill (data .tobytes ().hex (), 128 )
436
420
437
421
if transform is None :
438
422
matrix = "1 0 0 1 0 0"
0 commit comments