Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f27d41d

Browse files
committed
Support also lualatex in backend_pgf.PdfPages
1 parent 0354d65 commit f27d41d

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

lib/matplotlib/backends/backend_pgf.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,18 @@ def savefig(self, figure=None, **kwargs):
11761176
if self._n_figures == 0:
11771177
self._write_header(*figure.get_size_inches())
11781178
else:
1179-
self._file.write(
1180-
r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'.format(
1181-
*figure.get_size_inches()
1182-
).encode('utf-8') + b'\n'
1183-
)
1179+
if get_texcommand() == 'lualatex':
1180+
self._file.write(
1181+
r'\newpage\pagewidth={}in\pageheight={}in%'.format(
1182+
*figure.get_size_inches()
1183+
).encode('utf-8') + b'\n'
1184+
)
1185+
else:
1186+
self._file.write(
1187+
r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'.format(
1188+
*figure.get_size_inches()
1189+
).encode('utf-8') + b'\n'
1190+
)
11841191
figure.savefig(self._file, format="pgf", **kwargs)
11851192
self._n_figures += 1
11861193
finally:

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def check_for(texsystem):
4141
reason='xelatex + pgf is required')
4242
needs_pdflatex = pytest.mark.skipif(not check_for('pdflatex'),
4343
reason='pdflatex + pgf is required')
44+
needs_lualatex = pytest.mark.skipif(not check_for('lualatex'),
45+
reason='lualatex + pgf is required')
4446

4547

4648
def compare_figure(fname, savefig_kwargs={}, tol=0):
@@ -205,6 +207,7 @@ def test_pdf_pages():
205207
rc_pdflatex = {
206208
'font.family': 'serif',
207209
'pgf.rcfonts': False,
210+
'pgf.texsystem': 'pdflatex',
208211
}
209212
mpl.rcParams.update(rc_pdflatex)
210213

@@ -230,6 +233,7 @@ def test_pdf_pages_metadata():
230233
rc_pdflatex = {
231234
'font.family': 'serif',
232235
'pgf.rcfonts': False,
236+
'pgf.texsystem': 'xelatex',
233237
}
234238
mpl.rcParams.update(rc_pdflatex)
235239

@@ -239,6 +243,30 @@ def test_pdf_pages_metadata():
239243
fig.tight_layout()
240244

241245
md = {'author': 'me', 'title': 'Multipage PDF with pgf'}
242-
with PdfPages(os.path.join(result_dir, 'pdfpages.pdf'), metadata=md) as pdf:
246+
with PdfPages(os.path.join(result_dir, 'pdfpages_meta.pdf'), metadata=md) as pdf:
243247
pdf.savefig(fig)
244248
pdf.savefig(fig)
249+
250+
251+
@needs_lualatex
252+
@pytest.mark.style('default')
253+
@pytest.mark.backend('pgf')
254+
def test_pdf_pages_lualatex():
255+
rc_pdflatex = {
256+
'font.family': 'serif',
257+
'pgf.rcfonts': False,
258+
'pgf.texsystem': 'lualatex'
259+
}
260+
mpl.rcParams.update(rc_pdflatex)
261+
262+
fig = plt.figure()
263+
ax = fig.add_subplot(1, 1, 1)
264+
ax.plot(range(5))
265+
fig.tight_layout()
266+
267+
md = {'author': 'me', 'title': 'Multipage PDF with pgf'}
268+
with PdfPages(os.path.join(result_dir, 'pdfpages_lua.pdf'), metadata=md) as pdf:
269+
pdf.savefig(fig)
270+
pdf.savefig(fig)
271+
272+
raise Exception(result_dir)

0 commit comments

Comments
 (0)