66import numpy as np
77from matplotlib .path import Path
88
9+
910class HatchPatternBase :
1011 """
1112 The base class for a hatch pattern.
1213 """
1314 pass
1415
16+
1517class 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+
3034class 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+
4551class 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+
6270class 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+
8090class 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+
117132class 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+
124140class 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+
131148class 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+
138156class 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+
146165class 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+
169189def 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