Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,12 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
fill=rgbFace is not None)
writeln(self.fh, r"}")

maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX.
clip = (-maxcoord, -maxcoord, maxcoord, maxcoord)

# draw marker for each vertex
for point, code in path.iter_segments(trans, simplify=False):
for point, code in path.iter_segments(trans, simplify=False,
clip=clip):
x, y = point[0] * f, point[1] * f
writeln(self.fh, r"\begin{pgfscope}")
writeln(self.fh, r"\pgfsys@transformshift{%fin}{%fin}" % (x, y))
Expand Down Expand Up @@ -564,11 +568,13 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
f = 1. / self.dpi
# check for clip box / ignore clip for filled paths
bbox = gc.get_clip_rectangle() if gc else None
maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX.
if bbox and (rgbFace is None):
p1, p2 = bbox.get_points()
clip = (p1[0], p1[1], p2[0], p2[1])
clip = (max(p1[0], -maxcoord), max(p1[1], -maxcoord),
min(p2[0], maxcoord), min(p2[1], maxcoord))
else:
clip = None
clip = (-maxcoord, -maxcoord, maxcoord, maxcoord)
# build path
for points, code in path.iter_segments(transform, clip=clip):
if code == Path.MOVETO:
Expand Down
16 changes: 12 additions & 4 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,19 @@ def test_rcupdate():
@pytest.mark.style('default')
@pytest.mark.backend('pgf')
def test_pathclip():
np.random.seed(19680801)
mpl.rcParams.update({'font.family': 'serif', 'pgf.rcfonts': False})
plt.plot([0., 1e100], [0., 1e100])
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.savefig(BytesIO(), format="pdf") # No image comparison.
fig, axs = plt.subplots(1, 2)

axs[0].plot([0., 1e100], [0., 1e100])
axs[0].set_xlim(0, 1)
axs[0].set_ylim(0, 1)

axs[1].scatter([0, 1], [1, 1])
axs[1].hist(np.random.normal(size=1000), bins=20, range=[-10, 10])
axs[1].set_xscale('log')

fig.savefig(BytesIO(), format="pdf") # No image comparison.


# test mixed mode rendering
Expand Down