|
1 | 1 | """
|
2 |
| -.. _hatch_def: |
3 |
| -
|
4 | 2 | Module for generating hatch patterns.
|
5 | 3 |
|
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: |
7 | 8 |
|
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 |
9 | 13 | :align: center
|
10 | 14 | :alt: 8 squares, each showing the pattern corresponding to the hatch symbol:
|
11 | 15 | symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
|
|
14 | 18 | 'o' makes small unfilled circles, 'O' makes large unfilled circles,
|
15 | 19 | '.' makes small filled circles, and '*' makes a start with 5 points
|
16 | 20 |
|
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() |
20 | 47 |
|
21 | 48 | """
|
22 | 49 |
|
|
0 commit comments