I am adding patches in a plot inside matplotlib
using from matplotlib.patches import Patch
class. Please see the sample code below-
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
n = 5
hatch_1 = 'o'
hatch_2 = '.'
opacity = 0.4
bar_width = 0.4
y = np.random.randint(low=0, high=10, size=n)
x = np.arange(n)
bars = plt.bar(x, y, bar_width, align='center', alpha=opacity, fill=False)
for bar in bars:
bar.set_hatch(hatch_1)
y = np.random.randint(low=0, high=10, size=n)
bars = plt.bar(x + bar_width, y, bar_width,
align='center', alpha=opacity, fill=False)
for bar in bars:
bar.set_hatch(hatch_2)
patch_1 = Patch(fill=False, label='Hatch 1', hatch=hatch_1, alpha=opacity)
patch_2 = Patch(fill=False, label='Hatch 2', hatch=hatch_2, alpha=opacity)
# add legends
plt.legend(handles=[patch_1, patch_2], loc='upper right')
plt.show()
The hatches used for legends aren't visisble properly. I guess if I make the patches bigger, it will be visible.
How to make patches bigger?