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

(De-Duplication) linking validate hatch from hatch module#28076

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

Open
ShivamPathak99 wants to merge9 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromShivamPathak99:hatch_validation
Open
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
linking validate hatch from hatch module
  • Loading branch information
@ShivamPathak99
ShivamPathak99 committedApr 14, 2024
commit522f892df7621e89854be5de04352f5990b935e7
2 changes: 2 additions & 0 deletionslib/matplotlib/hatch.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,6 +182,8 @@ def __init__(self, hatch, density):
def _validate_hatch_pattern(hatch):
valid_hatch_patterns = set(r'-+|/\xXoO.*')
if hatch is not None:
if not isinstance(hatch, str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is an subtle API change that needs to be document as currently

b.set_hatch(('x','x'))

works. The docstring onPatch.set_hatch is not clear about the type on the input should be.

We do run the hatches through an lrucache so only hashable things work (and it looks like we used as a key in a dictionary before that).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Working on it,
I'm a bit lost on -

We do run the hatches through anlrucache so only hashable things work (and it looks like we used as a key in a dictionary before that).

Could you break it down for me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@staticmethod
@lru_cache(8)
defhatch(hatchpattern,density=6):
"""
Given a hatch specifier, *hatchpattern*, generates a `Path` that
can be used in a repeated hatching pattern. *density* is the
number of lines per unit square.
"""
frommatplotlib.hatchimportget_path
return (get_path(hatchpattern,density)
ifhatchpatternisnotNoneelseNone)

Is part of the code path betweenPatch.set_hatch and rendering a hatched patch. Thelru_cache means we will avoid re-computing the hatch path. Thelru_cache is backed by a dictionary (eventually) with the function parameters as the key so only inputs that are hashable can be used.

raise ValueError("Hatch pattern must be a string")
invalids = set(hatch).difference(valid_hatch_patterns)
if invalids:
valid = ''.join(sorted(valid_hatch_patterns))
Expand Down
15 changes: 2 additions & 13 deletionslib/matplotlib/rcsetup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@
from matplotlib.colors import Colormap, is_color_like
from matplotlib._fontconfig_pattern import parse_fontconfig_pattern
from matplotlib._enums import JoinStyle, CapStyle
from matplotlib.hatch import _validate_hatch_pattern

# Don't let the original cycler collide with our validating cycler
from cycler import Cycler, cycler as ccycler
Expand DownExpand Up@@ -617,19 +618,7 @@ def _validate_int_greaterequal0(s):
raise RuntimeError(f'Value must be >=0; got {s}')


def validate_hatch(s):
r"""
Validate a hatch pattern.
A hatch pattern string can have any sequence of the following
characters: ``\ / | - + * . x o O``.
"""
if not isinstance(s, str):
raise ValueError("Hatch pattern must be a string")
_api.check_isinstance(str, hatch_pattern=s)
unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O'}
if unknown:
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
return s
validate_hatch = _validate_hatch_pattern


validate_hatchlist = _listify_validator(validate_hatch)
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/rcsetup.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,7 @@ def _validate_linestyle(s: Any) -> LineStyleType: ...
def validate_markeverylist(s: Any) -> list[MarkEveryType]: ...
def validate_bbox(s: Any) -> Literal["tight", "standard"] | None: ...
def validate_sketch(s: Any) -> None | tuple[float, float, float]: ...
def validate_hatch(s: Any) -> str: ...
def validate_hatch(hatch: Any) -> str: ...
def validate_hatchlist(s: Any) -> list[str]: ...
def validate_dashlist(s: Any) -> list[list[float]]: ...

Expand Down
3 changes: 1 addition & 2 deletionslib/matplotlib/tests/test_rcparams.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -311,8 +311,7 @@ def generate_validator_testcases(valid):
'success': (('--|', '--|'), ('\\oO', '\\oO'),
('/+*/.x', '/+*/.x'), ('', '')),
'fail': (('--_', ValueError),
(8, ValueError),
('X', ValueError)),
(8, ValueError)),
},
{'validator': validate_colorlist,
'success': (('r,g,b', ['r', 'g', 'b']),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp