Skip to content

Surprising behavior of hatches in fill_between #11418

Open
@mwaskom

Description

@mwaskom

Bug report

Hatches are invisible in the output of ax.fill_between when color is specified. They are present when color is absent or when facecolor is used.

I found #9894 which might be related, but seems to be a much narrower

Code for reproduction

import matplotlib.pyplot as plt

f, ax = plt.subplots()
ax.fill_between([0, 1], [0, 1], hatch="//")
f.savefig("test1.png")

f, ax = plt.subplots()
ax.fill_between([0, 1], [0, 1], hatch="//", color="g")
f.savefig("test2.png")

f, ax = plt.subplots()
ax.fill_between([0, 1], [0, 1], hatch="//", facecolor="g")
f.savefig("test3.png")

Actual outcome

test1.png:
test1

test2.png:
test2

test3.png:
test3

Expected outcome

I expected test2.png to have black hatch marks. I think what's happening is that the color= kwarg is being picked up globally by the artist and so the hatches in test2.png are there, they just have the same green color as the background. Unfortunately I don't think any hatch metadata other than the string code gets added to the artist, so I can't check.

Having color= globally change both the face and edge color of the artist makes a certain amount of sense, and I think the hatches are mostly inheriting their attributes from the kwargs that set the edge aesthetics. So I think I understand what's happening, but it took me a long time to figure out why the hatch argument had, apparently, no effect. I'll also note that the hatch demo is using the color= kwarg, but with ax.bar.

Matplotlib version

  • Operating system: MacOS
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.6
  • Jupyter version (if applicable): NA
  • Other libraries: NA

This is a fresh install from conda to test, but I also saw it on matplotlib 2.2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesDocumentationbackend: pdfkeepItems to be ignored by the “Stale” Github Actiontopic: hatch

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions