Skip to content

Update hatch.py #27337

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
21 changes: 19 additions & 2 deletions lib/matplotlib/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ def __init__(self, hatch, density):
self.shape_codes[0] = Path.MOVETO
super().__init__(hatch, density)

class DashedHatch(HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines = int((hatch.count('_') + hatch.count('+')) * density)
self.num_vertices = self.num_lines * 2

def set_vertices_and_codes(self, vertices, codes):
steps, stepsize = np.linspace(0.0, 1.0, self.num_lines, False,
retstep=True)
steps += stepsize / 2.
vertices[0::2, 0] = steps
vertices[0::2, 1] = 0.0
vertices[1::2, 0] = steps
vertices[1::2, 1] = 1.0
codes[0::2] = Path.MOVETO
codes[1::2] = Path.LINETO

_hatch_types = [
HorizontalHatch,
VerticalHatch,
Expand All @@ -175,12 +191,13 @@ def __init__(self, hatch, density):
SmallCircles,
LargeCircles,
SmallFilledCircles,
Stars
Stars,
DashedHatch
]


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:
Expand Down