Skip to content

[ENH]: Different edgecolor and hatch color in bar plot #26074

Closed
@99991

Description

@99991

Problem

Colored edges look ugly:

colored hatch

I want bars with black edges and colored hatch:

colored hatch, black edge

My current workaround is to draw the bars twice, once with colored hatch and then a second time only with black edges:

import matplotlib.pyplot as plt
import numpy as np

width = 0.35
x = np.arange(4) + 1
y_red = [1, 3, 1, 4]
y_blue = [2, 2, 4, 1]

plt.bar(x - 0.5 * width, y_red, width, label="Height of red bars", hatch="////", facecolor=(0, 0, 0, 0), edgecolor="red")
plt.bar(x - 0.5 * width, y_red, width, facecolor=(0, 0, 0, 0), edgecolor="black")

plt.bar(x + 0.5 * width, y_blue, width, label="Height of blue bars", hatch=r"\\", facecolor=(0, 0, 0, 0), edgecolor="blue")
plt.bar(x + 0.5 * width, y_blue, width, facecolor=(0, 0, 0, 0), edgecolor="black")

plt.xticks(x)
plt.yticks([0, 1, 2, 3, 4])
plt.legend()
plt.savefig("hatch.png")
plt.show()

This workaround is not optimal because the legend is wrong.

Proposed solution

I propose a hatchcolor parameter which is independent of edgecolor.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions