Skip to main content

Posts

Showing posts from June, 2014

Filling between curves with color gradient or cmap in Matplotlib

I was trying to plot fill_between () in matplotlib with color gradient or any cmap defined in pyplot.  After googleing a lot i couldn't find any solution.  An alternative method is to use imshow() . I have created this example :  import numpy as np import matplotlib.pyplot as plt from matplotlib.path import Path from matplotlib.patches import PathPatch xx=np.arange(0,10,0.01) yy=xx*np.exp(-xx) path = Path(np.array([xx,yy]).transpose()) patch = PathPatch(path, facecolor='none') plt.gca().add_patch(patch) im = plt.imshow(xx.reshape(yy.size,1),  cmap=plt.cm.Reds,interpolation="bicubic",                 origin='lower',extent=[0,10,-0.0,0.40],aspect="auto", clip_path=patch, clip_on=True) #im.set_clip_path(patch) plt.savefig("out.png") Source: Matplotlib Example  http://matplotlib.org/examples/pylab_examples/image_clip_path.html