Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ def hatches_plot(ax, h):

# %%
# Hatching patterns can be repeated to increase the density.
#
# .. note::
# In regular (non-raw) Python strings, backslashes must be escaped:
# ``'\\\\'`` and ``r'\\'`` are both the two-character hatch ``\\``.
# Forgetting this silently halves the density — ``'\\\\\\'`` is only a
# triple hatch and thus sparser than ``'//////'``.

fig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))

hatches = ['//', '\\\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**']
hatches = ['//', r'\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**']

for ax, h in zip(axs.flat, hatches):
hatches_plot(ax, h)
Expand All @@ -48,7 +54,7 @@ def hatches_plot(ax, h):

fig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))

hatches = ['/o', '\\|', '|*', '-\\', '+o', 'x*', 'o-', 'O|', 'O.', '*-']
hatches = ['/o', r'\|', '|*', r'\-', '+o', 'x*', 'o-', 'O|', 'O.', '*-']

for ax, h in zip(axs.flat, hatches):
hatches_plot(ax, h)
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ def set_hatch(self, hatch):
hatchings are done. If same letter repeats, it increases the
density of hatching of that pattern.

In regular (non-raw) Python strings, backslashes must be doubled:
``'\\\\'`` and ``r'\\'`` are both a double back-diagonal hatch.

Parameters
----------
hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
Expand Down
Loading