Skip to content

Commit 9f2483c

Browse files
committed
Clarify stuff
1 parent 366c36e commit 9f2483c

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

lib/matplotlib/artist.py

-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ def set_sketch_params(self, scale=None, length=None, randomness=None):
679679
680680
Requires the following preamble when using the PGF backend:
681681
682-
\\usepackage{pgf}
683682
\\usepgfmodule{decorations}
684683
\\usepgflibrary{decorations.pathmorphing}
685684

lib/matplotlib/backends/backend_pgf.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,13 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
603603
# apply pgf decorators
604604
sketch_params = gc.get_sketch_params() if gc else None
605605
if sketch_params is not None:
606-
# Only "length" directly maps to "segment length" in PGF's API
607-
# The others are combined in "amplitude" -> Use "randomness" as
608-
# PRNG seed to allow the user to force the same shape on multiple
609-
# sketched lines
606+
# Only "length" directly maps to "segment length" in PGF's API.
607+
# PGF uses "amplitude" to pass the combined deviation in both x-
608+
# and y-direction, while matplotlib only varies the length of the
609+
# wiggle along the line ("randomness" and "length" parameters)
610+
# and has a separate "scale" argument for the amplitude.
611+
# -> Use "randomness" as PRNG seed to allow the user to force the
612+
# same shape on multiple sketched lines
610613
scale, length, randomness = sketch_params
611614
if scale is not None:
612615
writeln(self.fh, r"\pgfkeys{/pgf/decoration/.cd, "

lib/matplotlib/tests/test_backend_pgf.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -341,34 +341,24 @@ def test_minus_signs_with_tex(fig_test, fig_ref, texsystem):
341341

342342
@pytest.mark.backend("pgf")
343343
def test_sketch_params():
344-
fig, ax = plt.subplots(figsize=[3, 3])
344+
fig, ax = plt.subplots(figsize=(3, 3))
345345
ax.set_xticks([])
346346
ax.set_yticks([])
347347
ax.set_frame_on(False)
348-
handle = ax.plot([0, 1])[0]
348+
handle, = ax.plot([0, 1])
349349
handle.set_sketch_params(scale=5, length=30, randomness=42)
350350

351351
with BytesIO() as fd:
352352
fig.savefig(fd, format='pgf')
353353
buf = fd.getvalue().decode()
354354

355-
baseline = r"""\begin{pgfscope}%
356-
\pgfpathrectangle{\pgfqpoint{0.375000in}{0.300000in}}""" \
357-
r"""{\pgfqpoint{2.325000in}{2.400000in}}%
358-
\pgfusepath{clip}%
359-
\pgfsetrectcap%
360-
\pgfsetroundjoin%
361-
\pgfsetlinewidth{1.003750pt}%
362-
\definecolor{currentstroke}{rgb}{0.000000,0.000000,1.000000}%
363-
\pgfsetstrokecolor{currentstroke}%
364-
\pgfsetdash{}{0pt}%
365-
\pgfpathmoveto{\pgfqpoint{0.375000in}{0.300000in}}%
355+
baseline = r"""\pgfpathmoveto{\pgfqpoint{0.375000in}{0.300000in}}%
366356
\pgfpathlineto{\pgfqpoint{2.700000in}{2.700000in}}%
367357
\pgfkeys{/pgf/decoration/.cd, """ \
368358
r"""segment length = 0.300000in, amplitude = 0.050000in}%
369359
\pgfmathsetseed{42}%
370360
\pgfdecoratecurrentpath{random steps}%
371-
\pgfusepath{stroke}%
372-
\end{pgfscope}%"""
373-
# check that \pgfkeys{/pgf/decoration/.cd, ...} is in path definition
361+
\pgfusepath{stroke}%"""
362+
# \pgfdecoratecurrentpath must be after the path definition and before the
363+
# path is used (\pgfusepath)
374364
assert baseline in buf

0 commit comments

Comments
 (0)