From 9da6ad97a0e4245ab8c9f395547f7e52b3c4959a Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sat, 13 Apr 2024 21:41:12 +0530 Subject: [PATCH 1/7] added dashed pattern --- lib/matplotlib/hatch.py | 16 ++++++++++++++-- lib/matplotlib/hatch.pyi | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index 9ec88776cfd3..823b5aa93541 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -167,6 +167,17 @@ def __init__(self, hatch, density): self.shape_codes[0] = Path.MOVETO super().__init__(hatch, density) + +class Dashes(Shapes): + size = 0.35 + + def __init__(self, hatch, density): + self.num_rows = (hatch.count('_')) * density + path = Path([[0, 0], [1, 0]], [Path.MOVETO, Path.LINETO]) + self.shape_vertices = path.vertices + self.shape_codes = path.codes + super().__init__(hatch, density) + _hatch_types = [ HorizontalHatch, VerticalHatch, @@ -175,12 +186,13 @@ def __init__(self, hatch, density): SmallCircles, LargeCircles, SmallFilledCircles, - Stars + Stars, + Dashes ] def _validate_hatch_pattern(hatch): - valid_hatch_patterns = set(r'-+|/\xXoO.*') + valid_hatch_patterns = set(r'_-+|/\xXoO.*') if hatch is not None: invalids = set(hatch).difference(valid_hatch_patterns) if invalids: diff --git a/lib/matplotlib/hatch.pyi b/lib/matplotlib/hatch.pyi index 348cf5214984..488101689077 100644 --- a/lib/matplotlib/hatch.pyi +++ b/lib/matplotlib/hatch.pyi @@ -65,4 +65,11 @@ class Stars(Shapes): shape_codes: np.ndarray def __init__(self, hatch: str, density: int) -> None: ... +class Dashes(Shapes): + size: float + num_rows: int + shape_vertices: np.ndarray + shape_codes: np.ndarray + def __init__(self, hatch: str, density: int) -> None: ... + def get_path(hatchpattern: str, density: int = ...) -> Path: ... From 2817fb266e577dfb86485b7593a67dfc73caf6c3 Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:09:34 +0530 Subject: [PATCH 2/7] checks if hatch is string --- lib/matplotlib/hatch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index 823b5aa93541..b735393aa12b 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -194,6 +194,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): + raise ValueError("Hatch pattern must be a string") invalids = set(hatch).difference(valid_hatch_patterns) if invalids: valid = ''.join(sorted(valid_hatch_patterns)) From af4629ae0c150acb7842ec1dcc4e70fb0db75904 Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:00:49 +0530 Subject: [PATCH 3/7] validate_hatch from hatch module --- lib/matplotlib/rcsetup.py | 15 ++------------- lib/matplotlib/tests/test_rcparams.py | 3 +-- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a326d22f039a..605001c45c3e 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -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 @@ -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) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 4823df0ce250..9a40d232bd0d 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -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']), From f77da9f9631bc4c41f23a73d710fb1aea0b6d1de Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:31:41 +0530 Subject: [PATCH 4/7] change rcsetup.pyi , s:str --- lib/matplotlib/rcsetup.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.pyi b/lib/matplotlib/rcsetup.pyi index 1538dac7510e..fcbe319002bd 100644 --- a/lib/matplotlib/rcsetup.pyi +++ b/lib/matplotlib/rcsetup.pyi @@ -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(s: str) -> str: ... def validate_hatchlist(s: Any) -> list[str]: ... def validate_dashlist(s: Any) -> list[list[float]]: ... From 34be979db12fdacbe2aa1e24c7a46926d446a2bd Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:57:04 +0530 Subject: [PATCH 5/7] Revert "change rcsetup.pyi , s:str" This reverts commit f77da9f9631bc4c41f23a73d710fb1aea0b6d1de. --- lib/matplotlib/rcsetup.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.pyi b/lib/matplotlib/rcsetup.pyi index fcbe319002bd..1538dac7510e 100644 --- a/lib/matplotlib/rcsetup.pyi +++ b/lib/matplotlib/rcsetup.pyi @@ -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: str) -> str: ... +def validate_hatch(s: Any) -> str: ... def validate_hatchlist(s: Any) -> list[str]: ... def validate_dashlist(s: Any) -> list[list[float]]: ... From 9bb18c49400494bbb07327f0048cae4621f7d7fb Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:57:43 +0530 Subject: [PATCH 6/7] Revert "validate_hatch from hatch module" This reverts commit af4629ae0c150acb7842ec1dcc4e70fb0db75904. --- lib/matplotlib/rcsetup.py | 15 +++++++++++++-- lib/matplotlib/tests/test_rcparams.py | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 605001c45c3e..a326d22f039a 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -28,7 +28,6 @@ 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 @@ -618,7 +617,19 @@ def _validate_int_greaterequal0(s): raise RuntimeError(f'Value must be >=0; got {s}') -validate_hatch = _validate_hatch_pattern +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_hatchlist = _listify_validator(validate_hatch) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 9a40d232bd0d..4823df0ce250 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -311,7 +311,8 @@ def generate_validator_testcases(valid): 'success': (('--|', '--|'), ('\\oO', '\\oO'), ('/+*/.x', '/+*/.x'), ('', '')), 'fail': (('--_', ValueError), - (8, ValueError)), + (8, ValueError), + ('X', ValueError)), }, {'validator': validate_colorlist, 'success': (('r,g,b', ['r', 'g', 'b']), From d4a625c29160a9ed1da167a0ee0efbfff6475263 Mon Sep 17 00:00:00 2001 From: ShivamPathak99 <98941325+ShivamPathak99@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:59:16 +0530 Subject: [PATCH 7/7] Revert "checks if hatch is string" This reverts commit 2817fb266e577dfb86485b7593a67dfc73caf6c3. --- lib/matplotlib/hatch.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index b735393aa12b..823b5aa93541 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -194,8 +194,6 @@ 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): - raise ValueError("Hatch pattern must be a string") invalids = set(hatch).difference(valid_hatch_patterns) if invalids: valid = ''.join(sorted(valid_hatch_patterns))
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: