I would like to replicate the first plot in the next figure:

I am able to recreate the fist plot, using a single color, since its just an uniform distribution. However, I am not able to create a color palette as the figure, since when using:
color = plt.cm.viridis(P) patch.set_facecolor(color)
it restricts me to the range [0, 1]. Additionally, plt.histogram/sns.hisplot doesn't allow me to give an array of colors created using the intervals in the figure.
How could I reproduce this plot with the given colors?