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

Appearance settings

Commit 79e076d

Browse filesBrowse files
committed
Small cleanups to hatch.py.
- In Shapes.set_vertices_and_codes, handle `self.filled` just once at the beginning, and collect the vertices and codes parts in a list and concatenate them all at the end, rather than keeping track of a position in the buffers. - Make SmallFilledCirecles inherit from Circles rather that SmallCircles, with which it shares no attribute.
1 parent 579475b commit 79e076d
Copy full SHA for 79e076d

File tree

Expand file treeCollapse file tree

2 files changed

+15
-19
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-19
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``hatch.SmallFilledCircles`` now inherits from ``hatch.Circles``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... rather than from ``hatch.SmallCircles``.

‎lib/matplotlib/hatch.py

Copy file name to clipboardExpand all lines: lib/matplotlib/hatch.py
+12-19Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,24 @@ def __init__(self, hatch, density):
101101
def set_vertices_and_codes(self, vertices, codes):
102102
offset = 1.0 / self.num_rows
103103
shape_vertices = self.shape_vertices * offset * self.size
104-
if not self.filled:
105-
inner_vertices = shape_vertices[::-1] * 0.9
106104
shape_codes = self.shape_codes
107-
shape_size = len(shape_vertices)
108-
109-
cursor = 0
105+
if not self.filled:
106+
shape_vertices = np.concatenate( # Forward, then backward.
107+
[shape_vertices, shape_vertices[::-1] * 0.9])
108+
shape_codes = np.concatenate([shape_codes, shape_codes])
109+
vertices_parts = []
110+
codes_parts = []
110111
for row in range(self.num_rows + 1):
111112
if row % 2 == 0:
112113
cols = np.linspace(0, 1, self.num_rows + 1)
113114
else:
114115
cols = np.linspace(offset / 2, 1 - offset / 2, self.num_rows)
115116
row_pos = row * offset
116117
for col_pos in cols:
117-
vertices[cursor:cursor + shape_size] = (shape_vertices +
118-
(col_pos, row_pos))
119-
codes[cursor:cursor + shape_size] = shape_codes
120-
cursor += shape_size
121-
if not self.filled:
122-
vertices[cursor:cursor + shape_size] = (inner_vertices +
123-
(col_pos, row_pos))
124-
codes[cursor:cursor + shape_size] = shape_codes
125-
cursor += shape_size
118+
vertices_parts.append(shape_vertices + [col_pos, row_pos])
119+
codes_parts.append(shape_codes)
120+
np.concatenate(vertices_parts, out=vertices)
121+
np.concatenate(codes_parts, out=codes)
126122

127123

128124
class Circles(Shapes):
@@ -149,16 +145,13 @@ def __init__(self, hatch, density):
149145
super().__init__(hatch, density)
150146

151147

152-
# TODO: __init__ and class attributes override all attributes set by
153-
# SmallCircles. Should this class derive from Circles instead?
154-
class SmallFilledCircles(SmallCircles):
148+
class SmallFilledCircles(Circles):
155149
size = 0.1
156150
filled = True
157151

158152
def __init__(self, hatch, density):
159153
self.num_rows = (hatch.count('.')) * density
160-
# Not super().__init__!
161-
Circles.__init__(self, hatch, density)
154+
super().__init__(hatch, density)
162155

163156

164157
class Stars(Shapes):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.