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

Skip to content

Commit 3e9afc4

Browse files
committed
hatch figure
1 parent 37ce483 commit 3e9afc4

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
lines changed

doc/_embedded_plots/hatch_classes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import matplotlib.pyplot as plt
2+
from matplotlib.patches import Rectangle
3+
4+
fig, ax = plt.subplots()
5+
6+
pattern_to_class = {
7+
'/': 'NorthEastHatch',
8+
'\\': 'SouthEastHatch',
9+
'|': 'VerticalHatch',
10+
'-': 'HorizontalHatch',
11+
'+': 'VerticalHatch + HorizontalHatch',
12+
'x': 'NorthEastHatch + SouthEastHatch',
13+
'o': 'SmallCircles',
14+
'O': 'LargeCircles',
15+
'.': 'SmallFilledCircles',
16+
'*': 'Stars',
17+
}
18+
19+
for i, (hatch, classes) in enumerate(pattern_to_class.items()):
20+
r = Rectangle((0.1, i+0.5), 0.8, 0.8, fill=False, hatch=hatch*2)
21+
ax.add_patch(r)
22+
h = ax.annotate(f"'{hatch}'", xy=(1.2, .5), xycoords=r,
23+
family='monospace', va='center', ha='left')
24+
ax.annotate(pattern_to_class[hatch], xy=(1.5, .5), xycoords=h,
25+
family='monospace', va='center', ha='left', color='tab:blue')
26+
27+
ax.set(xlim=(0, 5), ylim=(0, i+1.5), yinverted=True)
28+
ax.set_axis_off()

lib/matplotlib/hatch.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,9 @@
66
77
The following hatching patterns are available, shown here at level 2 density:
88
9-
.. plot::
9+
.. plot:: _embedded_plots/hatch_classes.py
1010
:include-source: false
11-
:show-source-link: false
12-
:plot_formats: png
13-
:align: center
14-
:alt: 8 squares, each showing the pattern corresponding to the hatch symbol:
15-
symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
16-
'|' makes vertical lines, '-' makes horizontal lines,
17-
'+' makes a grid, 'X' makes a grid rotated 90 degrees,
18-
'o' makes small unfilled circles, 'O' makes large unfilled circles,
19-
'.' makes small filled circles, and '*' makes a start with 5 points
20-
21-
from matplotlib.patches import Rectangle
22-
fig, ax = plt.subplots()
23-
24-
pattern_to_class = {
25-
'/': 'NorthEastHatch',
26-
'\\': 'SouthEastHatch',
27-
'|': 'VerticalHatch',
28-
'-': 'HorizontalHatch',
29-
'+': 'VerticalHatch + HorizontalHatch',
30-
'x': 'NorthEastHatch + SouthEastHatch',
31-
'o': 'SmallCircles',
32-
'O': 'LargeCircles',
33-
'.': 'SmallFilledCircles',
34-
'*': 'Stars',
35-
}
36-
37-
for i, (hatch, classes) in enumerate(pattern_to_class.items()):
38-
r = Rectangle((0.1, i+0.5), 0.8, 0.8, fill=False, hatch=hatch*2)
39-
ax.add_patch(r)
40-
h = ax.annotate(f"'{hatch}'", xy=(1.2, .5), xycoords=r,
41-
family='monospace', va='center', ha='left')
42-
ax.annotate(pattern_to_class[hatch], xy=(1.5, .5), xycoords=h,
43-
family='monospace', va='center', ha='left', color='tab:blue')
44-
45-
ax.set(xlim=(0, 5), ylim=(0, i+1.5), yinverted=True)
46-
ax.set_axis_off()
11+
:alt: 8 squares, each showing the pattern corresponding to the hatch symbol: symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals, '|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid, 'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles, 'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes a start with 5 points
4712
4813
"""
4914

0 commit comments

Comments
 (0)