Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added a gallery example
  • Loading branch information
r3kste authored and Impaler343 committed Dec 22, 2024
commit 3155bc0369e0e22f652f6a67671472417923e2d2
43 changes: 43 additions & 0 deletions galleries/examples/shapes_and_collections/hatchcolor_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
===========================
Using hatchcolor in patches
===========================
Comment thread
Impaler343 marked this conversation as resolved.
Outdated

This example shows how to use the `hatchcolor` parameter to set the color of
the hatch. The `hatchcolor` parameter is available for `~.patches.Patch` and
Comment thread
Impaler343 marked this conversation as resolved.
Outdated
its children.
"""

import matplotlib.pyplot as plt
import numpy as np

from matplotlib.patches import Rectangle

fig, (ax1, ax2) = plt.subplots(1, 2)

# Rectangle with red hatch color and black edge color
ax1.add_patch(Rectangle((0.1, 0.5), 0.8, 0.3, hatch=".", hatchcolor='red',
edgecolor='black', lw=2))
# If hatchcolor is not passed, the hatch will inherit the edge color
ax1.add_patch(Rectangle((0.1, 0.1), 0.8, 0.3, hatch='x', edgecolor='orange', lw=2))

x = np.arange(1, 5)
y = np.arange(1, 5)

ax2.bar(x, y, facecolor='none', edgecolor='red', hatch='//', hatchcolor='blue')
ax2.set_xlim(0, 5)
ax2.set_ylim(0, 5)

plt.show()

# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.patches`
# - `matplotlib.patches.Polygon`
# - `matplotlib.axes.Axes.add_patch`
# - `matplotlib.axes.Axes.bar` / `matplotlib.pyplot.bar`