-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathhatch_classes.py
More file actions
28 lines (24 loc) · 914 Bytes
/
hatch_classes.py
File metadata and controls
28 lines (24 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, ax = plt.subplots()
pattern_to_class = {
'/': 'NorthEastHatch',
'\\': 'SouthEastHatch',
'|': 'VerticalHatch',
'-': 'HorizontalHatch',
'+': 'VerticalHatch + HorizontalHatch',
'x': 'NorthEastHatch + SouthEastHatch',
'o': 'SmallCircles',
'O': 'LargeCircles',
'.': 'SmallFilledCircles',
'*': 'Stars',
}
for i, (hatch, classes) in enumerate(pattern_to_class.items()):
r = Rectangle((0.1, i+0.5), 0.8, 0.8, fill=False, hatch=hatch*2)
ax.add_patch(r)
h = ax.annotate(f"'{hatch}'", xy=(1.2, .5), xycoords=r,
family='monospace', va='center', ha='left')
ax.annotate(pattern_to_class[hatch], xy=(1.5, .5), xycoords=h,
family='monospace', va='center', ha='left', color='tab:blue')
ax.set(xlim=(0, 5), ylim=(0, i+1.5), yinverted=True)
ax.set_axis_off()