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

Skip to content

Commit 37ce483

Browse files
committed
plot directive test
1 parent 4779f68 commit 37ce483

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

galleries/examples/shapes_and_collections/hatch_style_reference.py

Lines changed: 2 additions & 0 deletions
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: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""
2-
.. _hatch_def:
3-
42
Module for generating hatch patterns.
53
6-
The following hatching patterns are available, shown here at level 1 density:
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:
78
8-
.. image:: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_001.png
9+
.. plot::
10+
:include-source: false
11+
:show-source-link: false
12+
:plot_formats: png
913
:align: center
1014
:alt: 8 squares, each showing the pattern corresponding to the hatch symbol:
1115
symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
@@ -14,9 +18,32 @@
1418
'o' makes small unfilled circles, 'O' makes large unfilled circles,
1519
'.' makes small filled circles, and '*' makes a start with 5 points
1620
17-
18-
For examples of using the hatch API, see
19-
:ref:`sphx_glr_gallery_shapes_and_collections_hatch_style_reference.py`.
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()
2047
2148
"""
2249

0 commit comments

Comments
 (0)