Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

How to Set Hatch Color and Facecolor in Matplotlib fill_between

Use facecolor, edgecolor, hatch, and hatchcolor to style separate layers of a Matplotlib fill_between region.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set facecolor for the filled area, edgecolor for its boundary, hatch for the pattern, and hatchcolor for the pattern strokes. These are separate style properties on the collection returned by fill_between.

Set the fill, outline, and hatch colors separately

Pass the style arguments directly to fill_between. This example fills the region between zero and a sine curve where the curve is nonnegative:

As an Amazon Associate I earn from qualifying purchases.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x, y, color="navy")
ax.fill_between(
    x, 0, y,
    where=y >= 0,
    facecolor="lightblue",
    edgecolor="navy",
    hatch="//",
    hatchcolor="crimson",
)
plt.show()

The color values illustrate the documented arguments; the example is not a claim about a tested rendering result. The fill_between API documents the function and its collection properties.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What each style property controls

  • facecolor (or fc) colors the interior of the filled polygon. Face colors may be a single color or a sequence cycled over patches.
  • edgecolor (or ec) colors the polygon boundary. Set it to 'face' to match the face color.
  • hatch selects the pattern drawn across the filled area. A non-empty pattern is needed for hatch marks.
  • hatchcolor colors the hatch strokes. It accepts a color or 'edge', which uses the edge color.

Because hatch color is independent, it can differ from both the fill and outline. Matplotlib’s hatchcolor example demonstrates a red hatch with a black edge on a patch; the API and collections reference establish the corresponding collection styling for fill_between.

Choose a hatch pattern and density

Documented hatch characters include /, , |, -, +, x, o, O, ., and *. Combine characters for a composite pattern, or repeat one to increase its density—for example, '/' is sparser than '///'. The pattern is configured for the collection as a whole, not separately for each polygon member. See the hatch style reference.

If hatch marks do not appear

Check that hatch is non-empty, then check the rendering backend. Matplotlib’s hatch reference lists support in PS, PDF, SVG, macosx, and Agg; WX and Cairo are listed as unsupported. A hatch may therefore appear in one output path but not another if different backends are used.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Version considerations

The current stable documentation pages identify Matplotlib 3.11.2. The collections reference notes that Collection.set_color also sets hatch color as of version 3.11; that note concerns set_color and does not establish the first version that accepted the hatchcolor argument. If your code must support older Matplotlib installations, check the installed version’s API before relying on that argument. The collections API documents the property.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.