How to decouple hatch and edge color in Matplotlib?


To decouple hatch and edge color in matplotlib, we can use hatch color “o” and edge color “red”.−

Steps

  • Create a new figure or activate existing figure.
  • Add a subplot arrangement to the current axes.
  • Create two lists of data points.
  • Use bar() method with hatch and edgecolor.
  • To display the figure, use show() method.

Example

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax1 = fig.add_subplot(111)
x = [3, 6, 1]
y = [4, 6, 1]
ax1.bar(x, y, color='black', edgecolor='red', hatch="o", lw=1., zorder=0)
plt.show()

Output

Updated on: 06-May-2021

712 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements