@@ -1234,7 +1234,7 @@ def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
1234
1234
else :
1235
1235
raise ValueError ("outfile must be a path or a file-like object" )
1236
1236
1237
- self .figure .dpi = 72 # ignore the dpi kwarg
1237
+ self .figure .dpi = 72 # ignore the dpi kwarg
1238
1238
width , height = self .figure .get_size_inches ()
1239
1239
xo = 0
1240
1240
yo = 0
@@ -1262,18 +1262,17 @@ def write(self, *kl, **kwargs):
1262
1262
else :
1263
1263
self ._pswriter = io .StringIO ()
1264
1264
1265
-
1266
1265
# mixed mode rendering
1267
1266
_bbox_inches_restore = kwargs .pop ("bbox_inches_restore" , None )
1268
1267
ps_renderer = self ._renderer_class (width , height ,
1269
1268
self ._pswriter , imagedpi = dpi )
1270
1269
renderer = MixedModeRenderer (self .figure ,
1271
- width , height , dpi , ps_renderer ,
1272
- bbox_inches_restore = _bbox_inches_restore )
1270
+ width , height , dpi , ps_renderer ,
1271
+ bbox_inches_restore = _bbox_inches_restore )
1273
1272
1274
1273
self .figure .draw (renderer )
1275
1274
1276
- if dryrun : # return immediately if dryrun (tightbbox=True)
1275
+ if dryrun : # return immediately if dryrun (tightbbox=True)
1277
1276
return
1278
1277
1279
1278
self .figure .set_facecolor (origfacecolor )
@@ -1287,18 +1286,22 @@ def write(self, *kl, **kwargs):
1287
1286
", http://matplotlib.org/"
1288
1287
1289
1288
# write to a temp file, we'll move it to outfile when done
1289
+
1290
1290
fd , tmpfile = mkstemp ()
1291
+
1291
1292
with io .open (fd , 'w' , encoding = 'latin-1' ) as fh :
1292
1293
# write the Encapsulated PostScript headers
1293
1294
print ("%!PS-Adobe-3.0 EPSF-3.0" , file = fh )
1294
- if title : print ("%%Title: " + title , file = fh )
1295
+ if title :
1296
+ print ("%%Title: " + title , file = fh )
1295
1297
print ("%%Creator: " + creator_str , file = fh )
1296
1298
# get source date from SOURCE_DATE_EPOCH, if set
1297
1299
# See https://reproducible-builds.org/specs/source-date-epoch/
1298
1300
source_date_epoch = os .getenv ("SOURCE_DATE_EPOCH" )
1299
1301
if source_date_epoch :
1300
1302
source_date = datetime .datetime .utcfromtimestamp (
1301
- int (source_date_epoch ) ).strftime ("%a %b %d %H:%M:%S %Y" )
1303
+ int (source_date_epoch )).strftime (
1304
+ "%a %b %d %H:%M:%S %Y" )
1302
1305
else :
1303
1306
source_date = time .ctime ()
1304
1307
print ("%%CreationDate: " + source_date , file = fh )
@@ -1307,30 +1310,29 @@ def write(self, *kl, **kwargs):
1307
1310
1308
1311
Ndict = len (psDefs )
1309
1312
print ("%%BeginProlog" , file = fh )
1310
- print ("/mpldict %d dict def" % Ndict , file = fh )
1313
+ print ("/mpldict %d dict def" % Ndict , file = fh )
1311
1314
print ("mpldict begin" , file = fh )
1312
1315
for d in psDefs :
1313
- d = d .strip ()
1316
+ d = d .strip ()
1314
1317
for l in d .split ('\n ' ):
1315
1318
print (l .strip (), file = fh )
1316
1319
print ("end" , file = fh )
1317
1320
print ("%%EndProlog" , file = fh )
1318
1321
1319
1322
print ("mpldict begin" , file = fh )
1320
- # print >>fh, "gsave"
1321
- print ("%s translate" % _nums_to_str (xo , yo ), file = fh )
1322
- print ( "%s clipbox" % _nums_to_str ( width * 72 , height * 72 , 0 , 0 ), file = fh )
1323
+ print ( "%s translate" % _nums_to_str ( xo , yo ), file = fh )
1324
+ print ("%s clipbox" % _nums_to_str (width * 72 , height * 72 , 0 , 0 ),
1325
+ file = fh )
1323
1326
1324
1327
# write the figure
1325
1328
print (self ._pswriter .getvalue (), file = fh )
1326
1329
1327
1330
# write the trailer
1328
- #print >>fh, "grestore"
1329
1331
print ("end" , file = fh )
1330
1332
print ("showpage" , file = fh )
1331
1333
fh .flush ()
1332
1334
1333
- if isLandscape : # now we are ready to rotate
1335
+ if isLandscape : # now we are ready to rotate
1334
1336
isLandscape = True
1335
1337
width , height = height , width
1336
1338
bbox = (lly , llx , ury , urx )
@@ -1344,24 +1346,26 @@ def write(self, *kl, **kwargs):
1344
1346
paperWidth , paperHeight = paperHeight , paperWidth
1345
1347
else :
1346
1348
temp_papertype = _get_papertype (width , height )
1347
- if papertype == 'auto' :
1349
+ if papertype == 'auto' :
1348
1350
papertype = temp_papertype
1349
1351
paperWidth , paperHeight = papersize [temp_papertype ]
1350
1352
else :
1351
1353
paperWidth , paperHeight = papersize [papertype ]
1352
- if (width > paperWidth or height > paperHeight ) and isEPSF :
1354
+ if (width > paperWidth or height > paperHeight ) and isEPSF :
1353
1355
paperWidth , paperHeight = papersize [temp_papertype ]
1354
- verbose .report ('Your figure is too big to fit on %s paper. %s \
1355
- paper will be used to prevent clipping.'% (papertype , temp_papertype ), 'helpful' )
1356
-
1356
+ verbose .report (
1357
+ ('Your figure is too big to fit on %s paper. %s '
1358
+ 'paper will be used to prevent clipping.'
1359
+ ) % (papertype , temp_papertype ), 'helpful' )
1357
1360
1358
1361
texmanager = ps_renderer .get_texmanager ()
1359
1362
font_preamble = texmanager .get_font_preamble ()
1360
1363
custom_preamble = texmanager .get_custom_preamble ()
1361
1364
1362
1365
psfrag_rotated = convert_psfrags (tmpfile , ps_renderer .psfrag ,
1363
1366
font_preamble ,
1364
- custom_preamble , paperWidth , paperHeight ,
1367
+ custom_preamble , paperWidth ,
1368
+ paperHeight ,
1365
1369
orientation )
1366
1370
1367
1371
if rcParams ['ps.usedistiller' ] == 'ghostscript' :
@@ -1371,9 +1375,11 @@ def write(self, *kl, **kwargs):
1371
1375
xpdf_distill (tmpfile , isEPSF , ptype = papertype , bbox = bbox ,
1372
1376
rotated = psfrag_rotated )
1373
1377
elif rcParams ['text.usetex' ]:
1374
- if False : pass # for debugging
1375
- else : gs_distill (tmpfile , isEPSF , ptype = papertype , bbox = bbox ,
1376
- rotated = psfrag_rotated )
1378
+ if False :
1379
+ pass # for debugging
1380
+ else :
1381
+ gs_distill (tmpfile , isEPSF , ptype = papertype , bbox = bbox ,
1382
+ rotated = psfrag_rotated )
1377
1383
1378
1384
if is_writable_file_like (outfile ):
1379
1385
if file_requires_unicode (outfile ):
@@ -1389,6 +1395,7 @@ def write(self, *kl, **kwargs):
1389
1395
shutil .move (tmpfile , outfile )
1390
1396
os .chmod (outfile , mode )
1391
1397
1398
+
1392
1399
def convert_psfrags (tmpfile , psfrags , font_preamble , custom_preamble ,
1393
1400
paperWidth , paperHeight , orientation ):
1394
1401
"""
0 commit comments