Skip to content

Navigation Menu

Sign in
Appearance settings

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 afc26d8

Browse filesBrowse files
committed
Implement review comments of @anntzer
1 parent 8cb4d51 commit afc26d8
Copy full SHA for afc26d8

File tree

Expand file treeCollapse file tree

2 files changed

+20
-16
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-16
lines changed

‎lib/matplotlib/backends/backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pgf.py
+19-15Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,7 @@ def _run_latex(self):
11661166
% (texcommand, e.output.decode('utf-8')))
11671167

11681168
# copy file contents to target
1169-
with open(self._fname_pdf, "rb") as fh_src:
1170-
with open(self._outputfile, "wb") as fh:
1171-
shutil.copyfileobj(fh_src, fh)
1169+
shutil.copyfile(self._fname_pdf, self._outputfile)
11721170

11731171
def savefig(self, figure=None, **kwargs):
11741172
"""
@@ -1199,25 +1197,31 @@ def savefig(self, figure=None, **kwargs):
11991197
orig_canvas = figure.canvas
12001198
figure.canvas = FigureCanvasPgf(figure)
12011199

1200+
width, height = figure.get_size_inches()
12021201
if self._n_figures == 0:
1203-
self._write_header(*figure.get_size_inches())
1202+
self._write_header(width, height)
12041203
else:
1205-
if get_texcommand() == 'lualatex':
1206-
if _get_lualatex_version() > (0, 85, 0):
1207-
np = r'\newpage\pagewidth={}in\pageheight={}in%'
1208-
else:
1209-
np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
1210-
else:
1211-
np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
1212-
self._file.write(np.format(
1213-
*figure.get_size_inches()
1214-
).encode('utf-8') + b'\n'
1215-
)
1204+
self._file.write(self._build_newpage_command(width, height))
1205+
12161206
figure.savefig(self._file, format="pgf", **kwargs)
12171207
self._n_figures += 1
12181208
finally:
12191209
figure.canvas = orig_canvas
12201210

1211+
def _build_newpage_command(self, width, height):
1212+
'''LuaLaTeX from version 0.85 removed the `\pdf*` primitives,
1213+
so we need to check the lualatex version and use `\pagewidth` if
1214+
the version is 0.85 or newer
1215+
'''
1216+
texcommand = get_texcommand()
1217+
if texcommand == 'lualatex' and _get_lualatex_version() >= (0, 85, 0):
1218+
cmd = r'\page'
1219+
else:
1220+
cmd = r'\pdfpage'
1221+
1222+
newpage = r'\newpage{cmd}width={w}in,{cmd}height={h}in%' + '\n'
1223+
return newpage.format(cmd=cmd, w=width, h=height).encode('utf-8')
1224+
12211225
def get_pagecount(self):
12221226
"""
12231227
Returns the current number of pages in the multipage pdf file.

‎lib/matplotlib/tests/test_backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pgf.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_for(texsystem):
4242
needs_pdflatex = pytest.mark.skipif(not check_for('pdflatex'),
4343
reason='pdflatex + pgf is required')
4444
needs_lualatex = pytest.mark.skipif(not check_for('lualatex'),
45-
reason='lualatex + pgf is required')
45+
reason='lualatex + pgf is required')
4646

4747

4848
def compare_figure(fname, savefig_kwargs={}, tol=0):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.