8000 PEP8 fixes on hatch.py · matplotlib/matplotlib@4ef1e4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ef1e4d

Browse files
NelleVdmcdougall
authored andcommitted
PEP8 fixes on hatch.py
1 parent e10e7d7 commit 4ef1e4d

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

lib/matplotlib/hatch.py

Lines changed: 34 additions & 14 deletions
< 6D40 td data-grid-cell-id="diff-9fa22d18bda986f54317196aa0414a09252e8421779c006ed9ac51bf229ed1e9-110-123-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,52 @@
66
import numpy as np
77
from matplotlib.path import Path
88

9+
910
class HatchPatternBase:
1011
"""
1112
The base class for a hatch pattern.
1213
"""
1314
pass
1415

16+
1517
class HorizontalHatch(HatchPatternBase):
1618
def __init__(self, hatch, density):
1719
self.num_lines = (hatch.count('-') + hatch.count('+')) * density
1820
self.num_vertices = self.num_lines * 2
1921

2022
def set_vertices_and_codes(self, vertices, codes):
21-
steps, stepsize = np.linspace(0.0, 1.0, self.num_lines, False, retstep=True)
22-
steps += stepsize/2.
23+
steps, stepsize = np.linspace(0.0, 1.0, self.num_lines, False,
24+
retstep=True)
25+
steps += stepsize / 2.
2326
vertices[0::2, 0] = 0.0
2427
vertices[0::2, 1] = steps
2528
vertices[1::2, 0] = 1.0
2629
vertices[1::2, 1] = steps
2730
codes[0::2] = Path.MOVETO
2831
codes[1::2] = Path.LINETO
2932

33+
3034
class VerticalHatch(HatchPatternBase):
3135
def __init__(self, hatch, density):
3236
self.num_lines = (hatch.count('|') + hatch.count('+')) * density
3337
self.num_vertices = self.num_lines * 2
3438

3539
def set_vertices_and_codes(self, vertices, codes):
36-
steps, stepsize = np.linspace(0.0, 1.0, self.num_lines, False, retstep=True)
37-
steps += stepsize/2.
40+
steps, stepsize = np.linspace(0.0, 1.0, self.num_lines, False,
41+
retstep=True)
42+
steps += stepsize / 2.
3843
vertices[0::2, 0] = steps
3944
vertices[0::2, 1] = 0.0
4045
vertices[1::2, 0] = steps
4146
vertices[1::2, 1] = 1.0
4247
codes[0::2] = Path.MOVETO
4348
codes[1::2] = Path.LINETO
4449

50+
4551
class NorthEastHatch(HatchPatternBase):
4652
def __init__(self, hatch, density):
47-
self.num_lines = (hatch.count('/') + hatch.count('x') + hatch.count('X')) * density
53+
self.num_lines = (hatch.count('/') + hatch.count('x') +
54+
hatch.count('X')) * density
4855
if self.num_lines:
4956
self.num_vertices = (self.num_lines + 1) * 2
5057
else:
@@ -59,9 +66,11 @@ def set_vertices_and_codes(self, vertices, codes):
5966
codes[0::2] = Path.MOVETO
6067
codes[1::2] = Path.LINETO
6168

69+
6270
class SouthEastHatch(HatchPatternBase):
6371
def __init__(self, hatch, density):
64-
self.num_lines = (hatch.count('\\') + hatch.count('x') + hatch.count('X')) * density
72+
self.num_lines = (hatch.count('\\') + hatch.count('x') +
73+
hatch.count('X')) * density
6574
self.num_vertices = (self.num_lines + 1) * 2
6675
if self.num_lines:
6776
self.num_vertices = (self.num_lines + 1) * 2
@@ -77,8 +86,10 @@ def set_vertices_and_codes(self, vertices, codes):
7786
codes[0::2] = Path.MOVETO
7887
codes[1::2] = Path.LINETO
7988

89+
8090
class Shapes(HatchPatternBase):
8191
filled = False
92+
8293
def __init__(self, hatch, density):
8394
if self.num_rows == 0:
8495
self.num_shapes = 0
@@ -103,38 +114,45 @@ def set_vertices_and_codes(self, vertices, codes):
103114
if row % 2 == 0:
104115
cols = np.linspace(0.0, 1.0, self.num_rows + 1, True)
105116
else:
106-
cols = np.linspace(offset / 2.0, 1.0 - offset / 2.0, self.num_rows, True)
117+
cols = np.linspace(offset / 2.0, 1.0 - offset / 2.0,
118+
self.num_rows, True)
107119
row_pos = row * offset
108120
for col_pos in cols:
109-
vertices[cursor:cursor+shape_size] = shape_vertices + (col_pos, row_pos)
110-
codes[cursor:cursor+shape_size] = shape_codes
121+
vertices[cursor:cursor + shape_size] = (shape_vertices +
122+
(col_pos, row_pos))
123+
codes[cursor:cursor + shape_size] = shape_codes
111124
cursor += shape_size
112125
if not self.filled:
113-
vertices[cursor:cursor+shape_size] = inner_vertices + (col_pos, row_pos)
114-
codes[cursor:cursor+shape_size] = shape_codes
126+
vertices[cursor:cursor + shape_size] = (inner_vertices +
127+
(col_pos, row_pos))
128+
codes[cursor:cursor + shape_size] = shape_codes
115129
cursor += shape_size
116130

131+
117132
class Circles(Shapes):
118133
def __init__(self, hatch, density):
119134
path = Path.unit_circle()
120135
self.shape_vertices = path.vertices
121136
self.shape_codes = path.codes
122137
Shapes.__init__(self, hatch, density)
123138

139+
124140
class SmallCircles(Circles):
125141
size = 0.2
126142

127143
def __init__(self, hatch, density):
128144
self.num_rows = (hatch.count('o')) * density
129145
Circles.__init__(self, hatch, density)
130146

147+
131148
class LargeCircles(Circles):
132149
size = 0.35
133150

134151
def __init__(self, hatch, density):
135152
self.num_rows = (hatch.count('O')) * density
136153
Circles.__init__(self, hatch, density)
137154

155+
138156
class SmallFilledCircles(SmallCircles):
139157
size = 0.1
140158
filled = True
@@ -143,6 +161,7 @@ def __init__(self, hatch, density):
143161
self.num_rows = (hatch.count('.')) * density
144162
Circles.__init__(self, hatch, density)
145163

164+
146165
class Stars(Shapes):
147166
size = 1.0 / 3.0
148167
filled = True
@@ -166,23 +185,24 @@ def __init__(self, hatch, density):
166185
Stars
167186
]
168187

188+
169189
def get_path(hatchpattern, density=6):
170190
"""
171191
Given a hatch specifier, *hatchpattern*, generates Path to render
172192
the hatch in a unit square. *density* is the number of lines per
173193
unit square.
174194
"""
175-
size = 1.0
176195
density = int(density)
177196

178-
patterns = [hatch_type(hatchpattern, density) for hatch_type in _hatch_types]
197+
patterns = [hatch_type(hatchpattern, density)
198+
for hatch_type in _hatch_types]
179199
num_vertices = sum([pattern.num_vertices for pattern in patterns])
180200

181201
if num_vertices == 0:
182202
return Path(np.empty((0, 2)))
183203

184204
vertices = np.empty((num_vertices, 2))
185-
codes = np.empty((num_vertices,), np.uint8)
205+
codes = np.empty((num_vertices,), np.uint8)
186206

187207
cursor = 0
188208
for pattern in patterns:

0 commit comments

Comments
 (0)
0