To add a rectangle to my plot I usually use this code:
ret=Rectangle((x_l[i]-dx,y_l[i]-dx),width=dx,height=dx,facecolor='red',linestyle='solid')
ax=gca()
ax.add_patch(ret)
However I was wondering if was possible to give the color in a different way. I want my rectangle to be colored according to a colorbar. I’ll try explain it better. Every rectangle represent a cell and in every cell I define a scalar field. My scalar field ranges from min_val to max_val. I want every rectangle that I drawn to be color that correspond to the value of the scalar field in the rectangle.
You can draw every Rectangle with the color calculated by ColorMap: