79433123

Date: 2025-02-12 12:57:12
Score: 0.5
Natty:
Report link

To summarize the answers given in matplotlib bar graph black - how do I remove bar borders

There are two main ways to remove the white edgecolor: 1. Changing linewidth 2. Changing edgecolor

  1. Changing linewidth to zero => good results, added benefit of keeping hatch petterns

Mentioned in Docs of bar plot as

linewidth: float or array-like, optional Width of the bar edge(s). If 0, don't draw edges.

bar(. . . , linewidth=0)
  1. A: Changing edgecolor to the bar color => gives fuzzy results
bar(. . . , edgecolor="b")
  1. B: Changing edgecolor to "none" => also good results
bar(. . . , edgecolor="none")

Origin: The default edgecolor is black but for example setting seaborn style to whitegrid once will result in the described Problem.

Example to test:

import matplotlib.pyplot as plt
import seaborn as sns
#sns.set_style("whitegrid") # once called edgecolor will be white
fig, axs = plt.subplots(1, 4, figsize=(8, 3))

# Bars with hatching default edgecolor
axs[0].bar([1, 1.5, 2], [3, 5, 2], color='b', hatch='//')
axs[0].set_title('default')

# Bars with hatching and edgecolor="none" (hatching disappears)
axs[1].bar([1, 1.5, 2], [3, 5, 2], hatch='//', edgecolor="none", color='b')
axs[1].set_title('edgecolor="none"')

# Bars with hatching and edgecolor="b" (hatching disappears)
axs[2].bar([1, 1.5, 2], [3, 5, 2], hatch='//', edgecolor="b", color='b')
axs[2].set_title('edgecolor="b"')

# Bars with hatching and linewidth=0 (hatching remains)
axs[3].bar([1, 1.5, 2], [3, 5, 2], hatch='//', linewidth=0, color='b')
axs[3].set_title('linewidth=0')
plt.show()
Reasons:
  • Blacklisted phrase (1): how do I
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Lorenzothetall