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

MNT: clarify path.sketch rcparam format + test validate_sketch#26921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ksunden merged 3 commits intomatplotlib:mainfromstory645:mplrc
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
16 changes: 8 additions & 8 deletionslib/matplotlib/mpl-data/matplotlibrc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -669,14 +669,14 @@
#path.snap: True # When True, rectilinear axis-aligned paths will be snapped
# to the nearest pixel when certain criteria are met.
# When False, paths will never be snapped.
#path.sketch: None # May be None, or a3-tuple of the form:
# (scale, length, randomness).
#- *scale* is the amplitude of the wiggle
#perpendicular to the line (in pixels).
#- *length* is the length of the wiggle along the
#line (in pixels).
#- *randomness* is the factor by which the length is
#randomly scaled.
#path.sketch: None # May be None, or a tuple of the form:
# path.sketch:(scale, length, randomness)
# - *scale* is the amplitude of the wiggle
# perpendicular to the line (in pixels).
# - *length* is the length of the wiggle along the
# line (in pixels).
# - *randomness* is the factor by which the length is
# randomly scaled.
#path.effects:


Expand Down
9 changes: 6 additions & 3 deletionslib/matplotlib/rcsetup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -555,14 +555,17 @@ def validate_bbox(s):


def validate_sketch(s):

if isinstance(s, str):
s = s.lower()
s = s.lower().strip()
if s.startswith("(") and s.endswith(")"):
s = s[1:-1]
if s == 'none' or s is None:
return None
try:
return tuple(_listify_validator(validate_float, n=3)(s))
except ValueError:
raise ValueError("Expected a (scale, length, randomness)triplet")
except ValueError as exc:
raise ValueError("Expected a (scale, length, randomness)tuple") from exc


def _validate_greaterthan_minushalf(s):
Expand Down
24 changes: 24 additions & 0 deletionslib/matplotlib/tests/test_rcparams.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@
validate_int,
validate_markevery,
validate_stringlist,
validate_sketch,
_validate_linestyle,
_listify_validator)

Expand DownExpand Up@@ -628,3 +629,26 @@ def test_rcparams_legend_loc_from_file(tmpdir, value):

with mpl.rc_context(fname=rc_path):
assert mpl.rcParams["legend.loc"] == value


@pytest.mark.parametrize("value", [(1, 2, 3), '1, 2, 3', '(1, 2, 3)'])
def test_validate_sketch(value):
mpl.rcParams["path.sketch"] = value
assert mpl.rcParams["path.sketch"] == (1, 2, 3)
assert validate_sketch(value) == (1, 2, 3)


@pytest.mark.parametrize("value", [1, '1', '1 2 3'])
def test_validate_sketch_error(value):
with pytest.raises(ValueError, match="scale, length, randomness"):
validate_sketch(value)
with pytest.raises(ValueError, match="scale, length, randomness"):
mpl.rcParams["path.sketch"] = value


@pytest.mark.parametrize("value", ['1, 2, 3', '(1,2,3)'])
def test_rcparams_path_sketch_from_file(tmpdir, value):
rc_path = tmpdir.join("matplotlibrc")
rc_path.write(f"path.sketch: {value}")
with mpl.rc_context(fname=rc_path):
assert mpl.rcParams["path.sketch"] == (1, 2, 3)

[8]ページ先頭

©2009-2025 Movatter.jp