Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commiteeda705

Browse files
story645timhoffm
andcommitted
support tuple input for sketch
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent36a3f7f commiteeda705

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

‎lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@
669669
#path.snap: True # When True, rectilinear axis-aligned paths will be snapped
670670
# to the nearest pixel when certain criteria are met.
671671
# When False, paths will never be snapped.
672-
#path.sketch: None # May be None, or atriplet of the form:
673-
# path.sketch: scale, length, randomness
672+
#path.sketch: None # May be None, or atuple of the form:
673+
# path.sketch:(scale, length, randomness)
674674
# - *scale* is the amplitude of the wiggle
675675
# perpendicular to the line (in pixels).
676676
# - *length* is the length of the wiggle along the

‎lib/matplotlib/rcsetup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,17 @@ def validate_bbox(s):
555555

556556

557557
defvalidate_sketch(s):
558+
558559
ifisinstance(s,str):
559-
s=s.lower()
560+
s=s.lower().strip()
561+
ifs.startswith("(")ands.endswith(")"):
562+
s=s[1:-1]
560563
ifs=='none'orsisNone:
561564
returnNone
562565
try:
563566
returntuple(_listify_validator(validate_float,n=3)(s))
564-
exceptValueError:
565-
raiseValueError("Expected a'scale, length, randomness' triplet")
567+
exceptValueErrorasexc:
568+
raiseValueError("Expected a(scale, length, randomness) tuple")fromexc
566569

567570

568571
def_validate_greaterthan_minushalf(s):

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -631,36 +631,24 @@ def test_rcparams_legend_loc_from_file(tmpdir, value):
631631
assertmpl.rcParams["legend.loc"]==value
632632

633633

634-
@pytest.mark.parametrize("value", [(1,2,3),'1, 2, 3'])
634+
@pytest.mark.parametrize("value", [(1,2,3),'1, 2, 3','(1, 2, 3)'])
635635
deftest_validate_sketch(value):
636636
mpl.rcParams["path.sketch"]=value
637637
assertmpl.rcParams["path.sketch"]== (1,2,3)
638638
assertvalidate_sketch(value)== (1,2,3)
639639

640640

641-
@pytest.mark.parametrize("value", [1,'1','(1, 2, 3)'])
641+
@pytest.mark.parametrize("value", [1,'1','1 2 3'])
642642
deftest_validate_sketch_error(value):
643-
withpytest.raises(ValueError,match="'scale, length, randomness'"):
643+
withpytest.raises(ValueError,match="scale, length, randomness"):
644644
validate_sketch(value)
645-
withpytest.raises(ValueError,match="'scale, length, randomness'"):
645+
withpytest.raises(ValueError,match="scale, length, randomness"):
646646
mpl.rcParams["path.sketch"]=value
647647

648648

649-
deftest_rcparams_path_sketch_from_file(tmpdir):
649+
@pytest.mark.parametrize("value", ['1, 2, 3','(1,2,3)'])
650+
deftest_rcparams_path_sketch_from_file(tmpdir,value):
650651
rc_path=tmpdir.join("matplotlibrc")
651-
rc_path.write("path.sketch: 1, 2, 3")
652-
652+
rc_path.write(f"path.sketch:{value}")
653653
withmpl.rc_context(fname=rc_path):
654654
assertmpl.rcParams["path.sketch"]== (1,2,3)
655-
656-
657-
deftest_rcparams_path_sketch_from_file_error(tmpdir,caplog):
658-
# rcParams parser doesn't read a tuple rcfile entry
659-
rc_path=tmpdir.join("matplotlibrc")
660-
rc_path.write("path.sketch: (1, 2, 3)")
661-
662-
withmpl.rc_context(fname=rc_path):
663-
withcaplog.at_level("WARNING"):
664-
assertmpl.rcParams['path.sketch']isNone
665-
assert ("Expected a 'scale, length, randomness' triplet"
666-
incaplog.text)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp