I am trying to fill an area under my graph using fill_between
. I can get it to work with a single colour (say red), but I cannot get a gradient under the graph using a colourmap. From the fill_between
documentation I understand that I should be able to fill the area with a gradient using a colourmap but I cannot make it work. The colourmap is loaded properly, because I can access the separate colours from the loaded colourmap and fill the area with said colour.
Minimal working example:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
colourmap = mpl.cm.get_cmap('jet')
singlecolor = mpl.cm.get_cmap('jet')(500)
xx = np.arange(0,10,0.1)
yy = xx*np.exp(-xx)
plt.figure()
plt.plot(xx,yy)
plt.fill_between(xx,yy,cmap=colourmap,alpha=0.3)
# plt.fill_between(xx,yy,color=singlecolor,alpha=0.3)
plt.show()
I get no error messages, and I am using Python 3.8. How can I fill using a colourmap?