8000 Merge pull request #29644 from story645/hatches_api · matplotlib/matplotlib@52f659f · GitHub
[go: up one dir, main page]

Skip to content

Commit 52f659f

Browse files
authored
Merge pull request #29644 from story645/hatches_api
[Doc] Added images of hatches to hatch API page
2 parents cbd7523 + bc82744 commit 52f659f

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
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()

galleries/examples/shapes_and_collections/hatch_style_reference.py

Lines changed: 2 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
.. _hatch_def:
3+
24
=====================
35
Hatch style reference
46
=====================

lib/matplotlib/hatch.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
"""Contains classes for generating hatch patterns."""
1+
"""
2+
Module for generating hatch patterns.
3+
4+
For examples of using the hatch API, see
5+
:ref:`sphx_glr_gallery_shapes_and_collections_hatch_style_reference.py`.
6+
7+
The following hatching patterns are available, shown here at level 2 density:
8+
9+
.. plot:: _embedded_plots/hatch_classes.py
10+
:include-source: false
11+
:alt:
12+
8 squares, each showing the pattern corresponding to the hatch symbol:
13+
symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
14+
'|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid,
15+
'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles,
16+
'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes
17+
a star with 5 points
18+
"""
219

320
import numpy as np
421

lib/matplotlib/sphinxext/roles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def _mpltype_role(name, rawtext, text, lineno, inliner, options=None, content=No
125125
mpltype = text
126126
type_to_link_target = {
127127
'color': 'colors_def',
128+
'hatch': 'hatch_def',
128129
}
129130
if mpltype not in type_to_link_target:
130131
raise ValueError(f"Unknown mpltype: {mpltype!r}")

0 commit comments

Comments
 (0)
0