import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches importRectangle
plt.rcParams["figure.figsize"]=[7.50,3.50]
plt.rcParams["figure.autolayout"]=True
data = np.random.rayleigh(size=1000)*35
N, bins, patches = plt.hist(data,30, ec="k")
colors =["red","yellow","green"]for i inrange(0,len(bins)-1):
patches[i].set_facecolor(colors[i %len(colors)])
handles =[Rectangle((0,0),1,1, color=c, ec="k")for c in colors]
labels =["Red","Yellow","Green"]
plt.legend(handles, labels)
plt.show()