8000 backend_pgf: use the bounding box as clip rectangle (fixes #2586) · matplotlib/matplotlib@2c84d10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c84d10

Browse files
committed
backend_pgf: use the bounding box as clip rectangle (fixes #2586)
1 parent c54e2ba commit 2c84d10

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs):
799799
writeln(fh, r"\makeatletter")
800800
writeln(fh, r"\begin{pgfpicture}")
801801
writeln(fh, r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" % (w, h))
802-
writeln(fh, r"\pgfusepath{use as bounding box}")
802+
writeln(fh, r"\pgfusepath{use as bounding box, clip}")
803803
_bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
804804
renderer = MixedModeRenderer(self.figure, w, h, dpi,
805805
RendererPgf(self.figure, fh),
Binary file not shown.

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def backend_switcher(*args, **kwargs):
5858
return switch_backend_decorator
5959

6060

61-
def compare_figure(fname):
61+
def compare_figure(fname, savefig_kwargs={}):
6262
actual = os.path.join(result_dir, fname)
63-
plt.savefig(actual)
63+
plt.savefig(actual, **savefig_kwargs)
6464

6565
expected = os.path.join(result_dir, "expected_%s" % fname)
6666
shutil.copyfile(os.path.join(baseline_dir, fname), expected)
@@ -168,6 +168,24 @@ def test_mixedmode():
168168
compare_figure('pgf_mixedmode.pdf')
169169

170170

171+
# test bbox_inches clipping
172+
@switch_backend('pgf')
173+
def test_bbox_inches():
174+
if not check_for('xelatex'):
175+
raise SkipTest('xelatex + pgf is required')
176+
177+
Y, X = np.ogrid[-1:1:40j, -1:1:40j]
178+
fig = plt.figure()
179+
ax1 = fig.add_subplot(121)
180+
ax1.plot(range(5))
181+
ax2 = fig.add_subplot(122)
182+
ax2.plot(range(5))
183+
plt.tight_layout()
184+
185+
bbox = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
186+
compare_figure('pgf_bbox_inches.pdf', savefig_kwargs={'bbox_inches': bbox})
187+
188+
171189
if __name__ == '__main__':
172190
import nose
173191
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)
0