Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9fbd94

Browse files
committed
removed custom marker hatch
1 parent 45563ab commit b9fbd94

File tree

2 files changed

+2
-87
lines changed

2 files changed

+2
-87
lines changed

lib/matplotlib/hatch.py

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ def get_path(hatchpattern, density=6):
229229
"scale": 6,
230230
"weight": 1.0,
231231
"angle": 0.0,
232-
"random_rotation": False,
233-
"random_placement": False,
234-
"x_stagger": 0.5,
235-
"y_stagger": 0.0,
236-
"filled": True,
237232
}
238233

239234

@@ -273,94 +268,14 @@ def get_vertices_and_codes(self, hatch_buffer_scale=1.0):
273268
vertices, codes = np.empty((0, 2)), np.empty(0, Path.code_type)
274269

275270
if self.hatchpattern in hatchpatterns:
276-
# This is for line hatches
277271
for func in np.atleast_1d(hatchpatterns[self.hatchpattern]):
278272
vertices_part, codes_part = func(self)
279273
vertices_part = self._rotate_vertices(vertices_part)
280274

281275
vertices = np.concatenate((vertices, vertices_part))
282276
codes = np.concatenate((codes, codes_part))
283277
else:
284-
# This is for marker hatches
285-
if self.hatchpattern not in MarkerHatchStyle.marker_paths:
286-
raise ValueError(f"Unknown hatch pattern: {self.hatchpattern}")
287-
func = MarkerHatchStyle.marker_pattern
288-
vertices_part, codes_part = func(self)
289-
290-
vertices = np.concatenate((vertices, vertices_part))
291-
codes = np.concatenate((codes, codes_part))
292-
293-
return vertices, codes
294-
295-
296-
class MarkerHatchStyle(HatchStyle):
297-
marker_paths = {
298-
"o": Path.unit_circle,
299-
"O": Path.unit_circle,
300-
"*": (Path.unit_regular_star, 5), # TODO: is there a better way to do this?
301-
}
302-
303-
# TODO: saner defaults or no?
304-
marker_sizes = {
305-
"o": 0.2,
306-
"O": 0.35,
307-
"*": 1.0 / 3.0,
308-
}
309-
310-
def _get_marker_path(marker):
311-
func = np.atleast_1d(MarkerHatchStyle.marker_paths[marker])
312-
path = func[0](*func[1:])
313-
size = MarkerHatchStyle.marker_sizes.get(marker, attrs["weight"])
314-
315-
return Path(
316-
vertices=path.vertices * size,
317-
codes=path.codes,
318-
)
319-
320-
def marker_pattern(hatchstyle):
321-
size = hatchstyle.kwargs["weight"]
322-
num_rows = round(hatchstyle.kwargs["scale"] * hatchstyle.hatch_buffer_scale)
323-
path = MarkerHatchStyle._get_marker_path(hatchstyle.hatchpattern)
324-
marker_vertices = hatchstyle._rotate_vertices(
325-
path.vertices, scale_correction=False
326-
)
327-
marker_codes = path.codes
328-
329-
offset = 1.0 / num_rows
330-
marker_vertices = marker_vertices * offset * size
331-
x_stagger = hatchstyle.kwargs["x_stagger"] * offset
332-
y_stagger = hatchstyle.kwargs["y_stagger"] * offset
333-
334-
if not hatchstyle.kwargs["filled"]:
335-
marker_vertices = np.concatenate(
336-
[marker_vertices, marker_vertices[::-1] * 0.9]
337-
)
338-
marker_codes = np.concatenate([marker_codes, marker_codes])
339-
340-
vertices = np.empty((0, 2))
341-
codes = np.empty(0, Path.code_type)
342-
for row in range(num_rows + 1):
343-
row_pos = row * offset
344-
if row % 2 == 0:
345-
cols = np.linspace(0, 1, num_rows + 1)
346-
else:
347-
cols = np.linspace(x_stagger, 1 + x_stagger, num_rows + 1)
348-
349-
for i, col_pos in enumerate(cols):
350-
vertices_part = marker_vertices + [col_pos, row_pos]
351-
if i % 2 == 1:
352-
vertices_part += [0, y_stagger]
353-
354-
if hatchstyle.kwargs["random_rotation"]:
355-
vertices_part = hatchstyle._rotate_vertices(
356-
vertices_part, np.random.uniform(0, 360), scale_correction=False
357-
)
358-
359-
if hatchstyle.kwargs["random_placement"]:
360-
vertices_part += np.random.uniform(-offset / 4, offset / 4, 2)
361-
362-
vertices = np.concatenate((vertices, vertices_part))
363-
codes = np.concatenate((codes, marker_codes))
278+
_api.warn_external(f"Unknown hatch pattern: {self.hatchpattern}")
364279

365280
return vertices, codes
366281

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def hatchstyle(hatchstyles, hatch_buffer_scale=1.0):
10411041
for hatchstyle in hatchstyles:
10421042
hatchpattern = hatchstyle.get("hatch", None)
10431043
if hatchpattern is None:
1044-
print("Hatch pattern not provided.") # TODO: make this a warning
1044+
_api.warn_external("Hatch style must specify a hatch pattern.")
10451045
continue
10461046
hatchstyle = mpl.hatch.HatchStyle(hatchpattern, **hatchstyle)
10471047
verts, cods = hatchstyle.get_vertices_and_codes(hatch_buffer_scale)

0 commit comments

Comments
 (0)